Popular Posts Using Jekyll and GitHub Pages (or, Why I'm Moving To Django)

Why you can't easily do fancy things that require remembering state with GitHub Pages.

A couple days ago I was looking for a way to incorporate a “Recent Posts” and “Popular Posts” sidebar on posts in this blog, and on the listing page.

Recent posts are easy, as it’s as simple as adding something like the snippet below, to generate a list of the 5 most recent posts.

<div class="list-group">
  {% for post in site.posts limit:5 %}
    <a href="{{ post.url }}" class="list-group-item">{{ post.title }}</a>
  {% endfor %}
</div>

This generates a pretty list of post titles that link to that post. However, when I came to try to create the “Popular Posts” section, I came across a stumbling block. I personally knew which posts were popular from Google Analytics (and sometimes comments), but I had no idea how to get Jekyll to know which were most viewed (or most commented).

I came across a couple projects that claimed to be able to add the functionality. One example is this Octopress plugin which uses your page’s Google Pagerank to decide what your most popular posts. Obviously this is better than nothing, but doesn’t necessarily correlate with what your blog viewers are most interested in. I came across another that used a Google Analytics API to pull down pageviews, but I’d rather not tie functionality to my website analytics.

Instead, I’m deciding to migrate my blog to another platform. Jekyll has served me well up until now, but it feels just a little restrictive. There’s the lack of a Content Management System (CMS) - currently I just commit directly from GitHub when I want to post a new post. There’s the lack of flexibility - any time I want to add new functionality (such as newsletter sign-ups for example) I have to use some external service and tie it back in.

The platform I have decided to migrate to is Django, a web framework written in Python. I am already familiar with Django having used it in several projects before, so it seems a logical choice. Specifically, I’m investigating using a CMS called Mezzanine. Mezzanine is a collection of Django apps which come together to provide an easy-to-use, and out-of-the-box working CMS. It also promises to be highly customisable and extensible.

I’ll need to move away from GitHub Pages, since they only support static websites (and Jekyll based ones). But that’s okay. There’s plenty of options out there. The hosting service I’m looking to use once I’m ready to deploy is Digital Ocean. They provide easily scalable, cheap, and performant hosting - I’ve also used them on other projects such as my university team project.

Hopefully by my next post (but possibly the one after) you’ll be reading these posts on a wonderful Mezzanine-based website.

If you enjoyed this post, please check out my other blog posts.