Embed creating duplicate http / https topics

AI 生成的摘要

In the Support category, sckott reports that their Discourse embed is creating duplicate topics for blog posts at https://ropensci.org/blog/, likely because both http and https versions of the site are accessible without redirects. Falco identifies the root cause: Discourse treats http and https URLs as separate, triggering new topic creation for each. A suggested fix is implementing 301 redirects from http to https and enabling HSTS headers. sckott asks if the embed code can be modified to only use https, but Falco advises fixing the redirects instead, as the embed code’s discourseEmbedUrl should already enforce https. sckott thanks them, and later references a related meta thread 6, which codinghorror clarifies is unrelated. sckott offers to remove the link. Finally, techAPJ confirms the issue has been resolved in Discourse core via commit 9030d3e, which now handles http/https duplicates gracefully.

First, thanks for Discourse - awesome product.

I’m using embed in this category https://discuss.ropensci.org/c/blog for comments on our blog at rOpenSci | Blog

After first implementing the embed, it worked great. Recently, our forum has been creating duplicate topics (which I try to quickly delete to minimize annoying our users). Any thoughts on why duplicate topics are showing up?

I wonder if it’s at all related to how we make our site. We use Jekyll, render locally, then push to a server. I wonder if something about the way we update our site makes our forum think there’s a new topic to create even though the blog post linked to that topic is already linked to a topic already created.

Maybe there’s a way to prevent duplicate topics from being created as a work-around?

p.s. Duplicates were just created for three blog posts (the top 3 here https://discuss.ropensci.org/c/blog ) Duplicates seem to be created every few hours now.

It’s one for the http and one for the https version of the blog.

I believe if you add proper redirects (http sends 301 to https + HSTS headers) it won’t happen.

Makes sense, yep, ropensci.org still allows both http and https without redirecting http to https

Is there a way to in the meantime to make a fix in the embed code? Like only create a topic for https version of the URL? I have https hard-coded below, but I guess that doesn’t do it?

this is the code we have now:

<script type="text/javascript">
  DiscourseEmbed = { discourseUrl: 'https://discuss.ropensci.org/',
                     discourseEmbedUrl: 'https://ropensci.org{{ page.url }}' };

  (function() {
    var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
    d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
  })();
</script>

I think it’s easier to fix the redirects than to find why our embed code is ignoring the discourseEmbedUrl somewhere.

Okay, thanks for your help.

See also Embed Discourse comments on another website via Javascript - #174

That is not the same issue, that is about the “Show full post” button not duplicate topics.

want me to remove the link?

This is now fixed via: