[Obsidian Publish] Embedding Discourse comments

Using this feature, Discourse can automatically generate topics each time a new post is published, then embed an IFRAME of the replies to that topic as comments in the post. This is a feature I’m currently using in Ghost and would be missed when I migrate to Obsidian Publish.

To enable all Obsidian pages to have their own comments, we need Publish to insert the same following HTML snippet on all pages, but replace the value passed to discourseEmbedURL with the current Obsidian page’s URL.

<div id='discourse-comments'></div>

<script type="text/javascript">
  window.DiscourseEmbed = { discourseUrl: 'https://discourse.example.com/',
                     discourseEmbedUrl: 'http://example.com/blog/entry-123.html' };

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

Assuming there’s nothing unusual about Obsidian Publish’ layout, this should be all we need to do on the Obsidian end to make this work. When a page on the Publish site is visited for the first time, the IFRAME will try to load the comments, then crawl the contents of the page and prompt Discourse to create a new topic if the comments don’t exist yet.

So other than these HTML snippets, everything else is handled on Discourse’s end (as far as I’m aware).


A post was merged into an existing topic: Comment section on O. Publish