Skip to content
Switch branches/tags
Go to file

Latest commit


Git stats


Failed to load latest commit information.

Jekyll Blog Comments

Jekyll is a great tool for creating a statically generated blog but out of the box it doesn't have any support for comments.

This repo provides some tools to address that. Specifically;


The jekyll/_includes folder contains three files to be included in Jekyll site to render the comments and allow new ones, they are;

Copy these to your _includes folder then include comments.html from your blog post layout, e.g. my _layouts/post.html file looks like this;

layout: default
<div class="post {{ page.class }}">
  {% include item.html %}
  {{ page.content }}
  {% include comments.html %}

Configuring Jekyll for the templates

Finally you will need to add this end of your _config.yml so sorting and posting work:

emptyArray: []

  receiver: https://{{your-receiver-site}}/api/PostComment}}

Also add commenting: open to your defaults to switch the new comment form on. You can switch it back off per post by adding commenting: closed to the page or post front matter.

      path: ''
      type: pages
      layout: page
      author: damieng
      commenting: open
      path: '_posts'
      type: posts
      layout: post
      author: damieng
      commenting: open

Optional post-author highlighting

You need to make sure you have an author block for each post author so it can match when an author responds to his own post with additional styling;

    name: Damien Guard

If you do not have an author set on each post/page you can define a default one as shown in an example above.

Optional latest comments snippet

If you want to display the latest comments across all posts etc. then there are a few steps. The first combines all the comments together from their heirarchy:

{% assign unsorted_comments = site.emptyArray %}
{% for post_comments in %}
    {% for comment in post_comments[1] %}
        {% assign unsorted_comments = unsorted_comments | push: comment[1] %}
    {% endfor %}
{% endfor %}

Then you need to modify the whole collection as you want, e.g. sorting by date, reversing them so the most recent are first then getting the first 5.

{% assign latest_comments = unsorted_comments | sort: 'date'' | reverse | slice: 0, 5 %}

Then you can just loop over latest_comments as you normally would:

{% for comment in latest_comments %}
  <li id="{{ }}">
    {% include comment.html %}
  </li>{% endfor %}



  • Upload this file to your site
  • Access export-blog-comments.php call from your browser and wait for it to complete
  • Download the /comments/ folder over SSH and then remove it and the export-blog-comments.php from your server
  • Copy the /commments/ folder into your Jekyll _data/ folder



In order to process a new comment do you need a little bit of code running somewhere in the cloud to capture the form post, validate the parameters and write it to your repository. Here's what we have so far:

  • Azure + GitHub creates pull requests against your blog's GitHub repository with the new comment

Implementation notes

Data format

The comments are stored in your Jekyll site in individual yml files with the format _data/comments/{blog-post-slug}/{comment-id}.yml

The blog-post-slug must match the Jekyll slug for the post it relates to while the comment-id can be anything unique.

Each file should look something like this file, _data/comments/wordpress-exporting/12345.yml

id: 12345
name: Damien Guard
gravatar: dc72963e7279d34c85ed4c0b731ce5a9
date: 2007-12-18 18:51:55
message: "This is a great solution for 'dynamic' comments on a static blog!"