loteoo / hyperstatic

Routing, prerendering, code splitting and prefetching for hyperapp
https://hyperstatic.dev/
MIT License
59 stars 5 forks source link

Replace .replace(...) with .split(...).join('') #21

Closed nickspoons closed 4 years ago

nickspoons commented 4 years ago

string.replace(...) only replaces the first match when the pattern is a literal string (as opposed to a regular expression), see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

This patch uses string.split(...).join('') instead to ensure all instances of baseUrl are correctly removed from rendered pages.

An alternative could be to convert the pattern to a regular expression and use the 'g' flag:

const cleanedUpHtml = html.replace(new RegExp(baseUrl, 'g'), '')

However I think this version is simpler and clearer.

nickspoons commented 4 years ago

You're welcome! Thanks for the project!