Adding Disqus to a Jekyll Blog
A Jekyll blog is not backed by a database. Out of the box, there is no way for people to comment on or discuss blog posts. Disqus is a third party service that can be used to get around that limitation. This post covers adding Disqus to a Jekyll blog.
Software Versions
Instructions
First, install Jekyll and register your site with Disqus.
Add the following code to _includes/disqus.html. Remember to change the this.page.url line to the URL of your blog. The s.src line will need to point to your Disqus short name URL. Consider copying the Universal Embed Code directly from Disqus instead of this post.
Add the following line to the end of _layouts/post.html or anywhere else you want to display comments.
Add the following line to the YAML front matter of a post to enable comments on a post by post basis.
For example, the front matter of this post looks like this.
Optionally, to facilitate displaying comment counts add the following to _layouts/default.html before the closing body tag. Change SHORTNAME to the Disqus shortname you are using.
Add #disqus_thread to the end of a URL and Disqus will count the comments on the page the link points to. For example, my _layouts/post.html contains the following code. Note the comment count at the top of this post.
index.html contains the following code to display the comment count for each post in the list.
Note that moving a post from _drafts/ to _posts/ may change the URL of the post. This will cause any comments added to the draft to disappear. The Disqus Migration Tools can be used move comments to the new URL.
References:
- Jekyll
- Jekyll, Variables
- Jekyll, Templates
- Jekyll, YAML Front Matter
- Jekyll, Highlighting Liquid Code in a Liquid Template with Jekyll (Escape a Liquid Templating Tag)
- Jekyll, How I Created a Beautiful and Minimal Blog Using Jekyll, Github Pages, and poole
- Jekyll, Dynamic Links in jekyll
- Jekyll, Creating A Jekyll GitHub Pages Blog and Managing it With FreeBSD
- Disqus
- Disqus, Set Up Disqus On a New Site
- Disqus, Universal Embed Code
- Disqus, Jekyll Installation Instructions
- Disqus, Use Configuration Variables to Avoid Split Threads and “Missing” Comments
- Disqus, Migration Tools
- Disqus, Adding Disqus to your Jekyll
- Disqus, Jekyll Notes
- Disqus, Preserve Disqus Comments with Jekyll
- Google, Use canonical URLs