Discourse plugin for static site generators like Jekyll or Octopress

(Ben T) #94

The bad gateway errors is because I don’t really have any redundancy for a site I mostly use as a testing ground. :wink: I’m just using the new embed feature.

So, onwards and upwards! I’ve been thinking of how to allow users of the scripts I wrote to migrate over to the much more integrated embedded comments feature. It’s probably much simpler to move posts to newly generated topics. The above ghost script could be placed into a jekyll layout and reference {{ post.url }} instead. You may need to include the full URL before it as well.


(Erlend Sogge Heggen) #95

Actually that was directed at eviltrout (I edited in the part about you and your site afterwards which made things confusing) but it seems he’s up and running again too :wink:

Great to see this feature getting the attention it deserves!


(Robin Ward) #96

Do you mean a list of topics? Or all posts in a category? Either way it’s possible I’d just like to understand the use case first.

Late last week I corrupted my postgres database and only got it fixed on Saturday. Should work again :smile:


(Erlend Sogge Heggen) #97

Like when I want to achieve something similar to the WP plugin forums or ost.io.

I suppose I’m really talking about all posts in a category, yeah. But just the latest ones with a “Read more” type link to the full category purely within Discourse would be fine to.


(Robin Ward) #98

I’ve just added the ability to list reply counts on your blog index and archive pages as you can see here.

It works with a similar API to embedding comments:

<script type="text/javascript">
  var discourseUrl = "http://fishtank.eviltrout.com/";

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

If you embed this at the bottom of a document, it will look through all the links that have either an anchor to #discourse-comments or a data-discourse-embed-url attribute. If they have associated posts on discourse, it will update the text to say (x replies).

I’m pretty close to documenting all this up, but it wouldn’t hurt for more feedback on this feature first. Thanks!


(Arpit Jalan) #99

Thanks @eviltrout, this is exactly what I needed for my Jekyll blog, to replace Disqus with Discourse. Could you please publish the source code on Github. I would like to contribute in improving this.

1 Like

(Régis Hanol) #100

If you want to see how @eviltrout integrated it on his blog, you will find the source code on GitHub. Bear in mind that It uses Middleman and not Jekyll.

1 Like

(Robin Ward) #101

I hope to write up how it works this week. But like @zogstrip said you can view the source to Discourse or my blog any time on Github. No secrets here!


(Robin Ward) #102

Okay I’ve written up how to use Discourse on a static site on my blog:


We might want to move some of the blog entry into our official documentation.


(Eric Carlson) #103

@eviltrout First, let me say that this is great! It worked (almost) as-documented on my Jekyll site out of the box. When it didn’t quite work, I looked at your blog’s source and found that you hadn’t mentioned the need for a <div id="discourse-comments"></div> in the blog post template to act as a container for the comments. Once that was there, it worked great.

Beyond that, something that would make this even better would be the ability to change the css for the embedded content. My blog site has a dark theme, and the light theme of what is embedded looks rather out of place. Discourse emits an iframe for the comments, and because my blog and my Discourse site are on different hosts, same origin policy prevents me changing the css of anything inside the iframe.

It would be great if it were possible to customize the css of emitted content at the Discourse end. It could be done through the admin interface much the same was as header customization is done now.


(Eric Carlson) #104

I have also just noticed that the post created at the Discourse end when you first try to fetch comments is uncategorized. It would be good to be able to give these a specified category automatically (e.g., ‘blog’).


(Erlend Sogge Heggen) #105

The 1 reply button just confused me. It doesn’t seem to do anything besides bumping me down to the next reply. I’m guessing it might have other uses when there are hidden replies, but when there aren’t, I think the button itself should be hidden. The in rely to eviltrout text in the actual reply is enough info.


(Robin Ward) #106

I’ve updated the blog to add the div - Oops!

As for styling it, that is a great idea and I’ll try to get it done soon.

This is also a good idea!


(Eric Carlson) #107

I’ve just issued a pull request on discourse/discourse that adds a site setting called embed_category. The setting is an empty string by default, so created topics are uncategorized unless you tell it otherwise. Also, if the specified category does not exist for some reason, the created topic is uncategorized.

In some ways it would also be good to allow an option string on the URL of the embed request to specify/override the category. This would allow posts retrieved from different blog sites to be assigned different categories, for example. On the other hand, implementing this appears to entail a lot more code because the category passed in as a URL option would then need to be passed along through several layers of code before finally being used to create the topic. Given that the current embed implementation appears only to allow one remote host to request embedded comments from a Discourse site (i.e., the embeddable_host setting), it seems acceptable that all topics created site-wide via retrieval from blogs are given the same category (i.e., the new embed_category setting).


(Robin Ward) #108

Thanks so much for this :smile:

I think the site setting is a good solution for now. If people need it to be more complicated in the future we can build on top of it.


(Rodrigo Farcas) #109

Hey, anyone has a live example of this working?


(Kane York) #110

Yep, @eviltrout’s blog: Embedding Discourse in Static Sites - Evil Trout’s Blog


(Rodrigo Farcas) #111

Why embeding discourse comments needs a “Reply here” link, instead of showing directly the reply-box?


(Jeff Atwood) #112

We don’t do on-page replies. You must enter the clubhouse to join the community before replying. Sit down at our dinner table with us and let’s have a discussion. Don’t just yell at us from across the room.


(Rodrigo Farcas) #113

How I do enter the clubhouse?