Gridsome: WordPress Wysiwyg links

Created on 12 Jun 2019  路  3Comments  路  Source: gridsome/gridsome

Summary

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.

Motivation

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.

enhancement

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.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,

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

renestalder picture renestalder  路  3Comments

kaceo picture kaceo  路  3Comments

tomtev picture tomtev  路  3Comments

ShahrukhAhmed89 picture ShahrukhAhmed89  路  3Comments

nolfranklin picture nolfranklin  路  3Comments