"Show Full Post" button doesn't work in subfolder installations

Hey guys, I see the trailing slash has struck again :slight_smile:

[trailing slashes are] the principal issue it appears. When using Embed Discourse comments on another website via Javascript you control that via a parameter, it’s super easy to fix.

Just at note that all topic embeds in Discourse strip trailing slashes from the embed_url; see TopicEmbed.normalize_url. As a result of a separate case involving the intersection of javascript embeds and WP Discourse embeds we standardised this handling across both methods of embeds. See Apply TopicEmbed url normalisation to embed urls inserted in the PostCreator by angusmcleod · Pull Request #30641 · discourse/discourse · GitHub

@Thiago_Mobilon In the course of this move did you also update your Discourse? It may be that we’re seeing the application of the standardisation of embed_url normalization to WP Discourse embeds being applied here as a result of an update of your Discourse, which occurred at the same time as the move to the subfolder installation. What version of Discourse are you currently running? (and what version were you running prior to the move, if you know that?)

Just a side note that when I run these two commands locally on the latest version of Discourse, I’m getting the same result, namely the HTML body of the article

# with trailing slash
TopicEmbed.find_remote("https://tecnoblog.net/noticias/governo-renova-app-da-cnh-para-baratear-obtencao-do-documento/")

# without trailing slash
TopicEmbed.find_remote("https://tecnoblog.net/noticias/governo-renova-app-da-cnh-para-baratear-obtencao-do-documento")

# produces the same result

Did you perhaps make a change on the Wordpress side of things?

** edit Ah reading this topic a bit more closely I see that your issue is perhaps not to do with your move of Discourse to a subfolder installation, or trailing slashes, rather it is perhaps your migration of your Wordpress urls, i.e.

For example, in this post, the url used to be:

https://tecnoblog.net/486925/o-que-e-pirataria-digital/

Now, it changed to:

https://tecnoblog.net/responde/o-que-e-pirataria-digital/

So perhaps the issue is that you have topic_embeds.embed_url with your old url structure and FinalDestination is not resolving the new urls for whatever reason (i.e. it’s unable to follow a redirect)

In that case you will either need to ensure that your old blog urls redirect to your new blog urls, or you’ll need to migrate the topic_embeds.embed_url. On the migration front, note that your script is incorrect, e.g. topic.custom_fields["embed_url"] is not where the embed_url is stored.

Here’s what I would suggest if you want to go the migration route (as opposed to redirecting your old blog urls to the new ones). First, confirm your issue is an incorrect blog url format in topic_embeds.embed_url by looking at an example, e.g. TopicEmbed.find_by(topic_id: 157441). Then, if you see that the issue is indeed that you have the old url format saved in that column, run this to update all of the old format embed_urls in a specific category:

category_id = # enter a category id here
TopicEmbed.joins(:topic).where(topics: { category_id: category_id  }).find_each do |embed|
   new_url = embed.embed_url.sub(%r{/\d+/}, "/responde/")
   embed.update!(embed_url: new_url) if new_url != embed.embed_url
 end

Note that the regex substitution of the old format to the new (sub(%r{/\d+/}, "/responde/")) is just a guess based on the example you provided. You can test the effect of that on your real urls here: https://regex101.com/

1 Like