When a wordpress wysiwyg content is fetched it can contain links to internal pages. If the wordpress installation and the static site don't share domain the links become incorrect. They lead to the wordpress pages which with vue and gridsome are most probably useless.
We need some sort of plugin that rewrites incorrect urls and replaces them with the correct ones.
Gridsome source-wordpress needs this in order to help de developers on their neverending fight on preventing the clients from destroying the sites from the wordpress cms.
Hey @martifenosa
So, gridsome source-wordpress does not touch $post.content. It just renders it inside a v-html.
You could transform the post content and replace the backend URL with the production site URL. I could make a PR if @hjvedvik agrees.
Imagine:
source-wordpress settings baseUrl = https://backend.my-site.com
gridsome config siteUrl = https://my-site.com
Then we could have a setting on source-wordpress plugin that says:
replaceBaseUrlWithSiteUrlOnPostContent = {boolean}
Currently, I am running my own version of source-wordpress on gridsome.server.js with a bunch of modifications. You could do the same if the patch is not possible.
Also, if you have good control over your backend deployment (nginx / apache) you could make the website answer on https://my-site.com/ and the backend answer on https://my-site.com/wp-admin/.
And on a last note, if you do have control over your backend, you should rewrite all urls from the backend domain to the frontend domain just to be safe. Its better to have a 301 then to have the user landing somewhere else.
Hope it helps,
@dominiquedutra That would be great. Finding and replacing URLs is quite easy to do in a computed property before passing it to v-html. But it might be a good idea to let the plugin do it instead. A replaceUrls option would be good, which defaults to true :)
Submitted a rudimentary PR but I couldn't see a optimized way of doing this.
Hope it helps.
Most helpful comment
Hey @martifenosa
So, gridsome source-wordpress does not touch $post.content. It just renders it inside a v-html.
You could transform the post content and replace the backend URL with the production site URL. I could make a PR if @hjvedvik agrees.
Imagine:
source-wordpress settings baseUrl = https://backend.my-site.comgridsome config siteUrl = https://my-site.comThen we could have a setting on source-wordpress plugin that says:
replaceBaseUrlWithSiteUrlOnPostContent = {boolean}Currently, I am running my own version of source-wordpress on gridsome.server.js with a bunch of modifications. You could do the same if the patch is not possible.
Also, if you have good control over your backend deployment (nginx / apache) you could make the website answer on
https://my-site.com/and the backend answer onhttps://my-site.com/wp-admin/.And on a last note, if you do have control over your backend, you should rewrite all urls from the backend domain to the frontend domain just to be safe. Its better to have a 301 then to have the user landing somewhere else.
Hope it helps,