Hugo plugin that lets you use Discourse as the community engine for a Hugo blog

I’d like to have Hugo plugin that lets you use Discourse as the community engine for a Hugo blog.
Something like the following wordpress example: https://github.com/discourse/wp-discourse.

This should do the trick—but I don’t have a Discourse instance to test it against (I haven’t yet put my own site up yet, and I’m not planning on enabling comments), if you have set params.discourseUrl in your top-level config. You’ll need to modify your template to add {{ partial "discourse.html" . }} to all of the appropriate single.html files.

<!-- layouts/partials/discourse.html -->
<div id="discourse-comments"></div>

<script type="text/javascript">
  var discourseUrl = '{{ .Site.Params.discourseUrl }}',
  discourseEmbedUrl =  '{{ .Permalink }}';

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

This is based on http://eviltrout.com/2014/01/22/embedding-discourse.html.

3 Likes

Thank you for sharing, … It sounds great !

There’s a more up-to-date version of this guide available on Meta now:

1 Like