تضمين تعليقات Discourse على موقع آخر عبر JavaScript

I tried to implement this today but there are some problems for me:

  • In the forum post, the URL derived (from discourseEmbedUrl?) is lowercased(), breaking case-sensitive URLs in the link following the text “This is a companion discussion topic for the original entry at …”
  • On the first page load, the embed says “Loading discussion…” and hangs. Second page load everything works.
  • Page thrashing: when the iframe is loading, it will have a default height, but if there are no comments found, the height shrinks back down to only display one line with “Start Discussion”. This makes the “loading discussion” bug worse, because it holds open large vertical height
  • It would be nice if the data scraped from embed’s parent could favor a meta tag instead of textifying the whole page, I suppose this is more generalized discourse behavior

The biggest surprise was learning that every time you visit a URL with an embed, a new topic is created. This is in OP:

The only solution I can think of is hacky, relying on short term SSR/caching to ping the embed endpoint:

so I think the logic would be:

  1. check $discourse/embed/info?embed_url=$link

  2. if the topic exists, show the embed as usual.

  3. if not, show a “start conversation” button that links to $discourse/new-topic?subject=$link.

Would that work, or is there some other linkage that needs to take place?