gatsbyjs / gatsby-source-wordpress-experimental

The upcoming v4 of gatsby-source-wordpress, currently in beta
MIT License
385 stars 100 forks source link

fix: relative urls inside html content to include prefix #328

Open henrikwirth opened 4 years ago

henrikwirth commented 4 years ago

Issue: #310

So when using pathPrefix, relativeUrls inside html don't get prefixed. This doesn't make much sense, since I might want to create content in WordPress with relative URLs that don't use the prefix yet, so later I can change the prefix to whatever I want.

Where this comes in handy and was really necessary, is a multisite setup with multiple translations.

What this fix does: When pathPrefix is used and the pluginOption.prefixRelativeUrls is active, the nodeStrings will be searched for elements, that start with href= and include a url that starts with /.

Excluded by the regex are urls that start with: pathPrefix|/wp-content|/wp-admin|/wp-includes|//

So we don't want prefix already prefixed URLs or URLs that start with a double //.

The other branch that was branched from v1.7.9 can be found here since I need a v1.7.10: https://github.com/henrikwirth/gatsby-source-wordpress-experimental/tree/fix-relative-urls-in-html

henrikwirth commented 4 years ago

Maybe I could leave /wp-content|/wp-admin|/wp-includes outside of the regex, since we are not looking for wpUrl in that regex.