progital / gatsby-wpgraphql-inline-images

Solution for Gatsby and WPGraphQL sourced content. Downloads images locally.
MIT License
35 stars 12 forks source link

add correction if wordPressUrl is a subdirectory #15

Closed pehaa closed 5 years ago

pehaa commented 5 years ago

Hi! Huge thanks you for this plugin! There is a problem if WordPress is installed in a subdirectory (for example https://mydomain.com/subdirectory). In that case the internal links are not parsed correctly to gatsby Links. What happens is that https://mydomain.com/subdirectory/page1 becomes /subdirectory/page1 and not /page1

The subdirectoryCorrection function should fix it.

progital commented 5 years ago

Hi! Thank you for taking time and doing a PR. Let me review it and I'll get back to you.

progital commented 5 years ago

Great, thanks for catching this. Just a small correction. I don't like long regexes because time is needed to understand them when seen in the code. That's why I used URIParser to make all url manipulations easier to read. What if instead of using a regex to get the subdirectory we get path() from the WordPress url and then replace that path with / in the link url. Does it make sense? Should be much fewer lines of code.