Jekyll Upgrades and Liquid Templates

Today I learned:

Upgrading Jekyll from 2.x to 3.x

The upgrade itself is simple: In Terminal, run gem update jekyll. Use sudo if you run into permissions issues like I did.

If you use pagination in any of your templates, you’ll now have to add gems: [jekyll-paginate] to the # Plugins section of your _config.yaml or else your site won’t compile. This wasn’t necessary in 2.x.

Making an index for my TIL posts in Liquid

I wanted to have an index for my TIL posts that was organized in two ways: reverse chronologically and by tag. Here is how I’m handling that with Liquid:

### Recent TIL Posts
{% for post in site.categories['TIL'] %}
{{ post.date | date: '%d %b %y' }}: {{ post.url }}">{{ post.title }}
{% endfor %}
--- ### TIL posts by category {% for tag in site.tags %} {% assign t = tag | first %} {% assign posts = tag | last %} #### {{ t }}
{% for post in posts %} {% if post.tags contains t %}
{{ post.date | date: '%d %b %y' }}: {{ post.url }}">{{ post.title }}
{% endif %} {% endfor %}
{% endfor %}

Notes:

The general structure of the tags method comes from Joe Kampschmidt. I started searching when it didn’t work the same way as the categories method I wrote earlier.

This method for displaying tags works because I’m only tagging my TIL posts. Everything else goes into categories. If I were to tag other kinds of posts, I’d need to first limit by posts in site.categories['TIL']

Category names are case sensitive.

You can display raw Liquid markup without it rendering by wrapping it in {%raw%} and {%endraw%}.