I’ve just reorganized the TIL page to alphabetically
list all the categories I’m writing about. TIL is a custom collection
of this Jekyll website[1], so I couldn’t simply use site.categories to
get categories of this collection, even though it uses categories in its front matter:
---
layout: post
title: Listing categories of Jekyll collection
categories: jekyll
---
I had to resort to some Liquid hackery.
{%assigntil=site.til%}
{%assigncategories=til|map:'categories'|join:','|split:','|group_by:category|sort:"name"%}
{%forcategoryincategories%}
<h2>{{category.name|capitalize}}</h2>
{%assignposts=til|where:"categories",category.name|sort:"date"|reverse%}
{%forpostinposts%}
<li>
<a href="{{post.url}}">
{{post.title}}
</a>
<p>
{{post.date|date:"%B %-d, %Y"}}
</p>
</li>
{%endfor%}
{%endfor%}
The end result:
The biggest problem with this approach is the constraint of a single category per post. If multiple categories are used, the post will get listed multiple times in the TIL index, one time for each category.