So it took me a while to figure out how to implement tags in Jekyll the way I wanted.
What I wanted was two-fold:
http://mahiwaga.pw/tag/*tag* would link to a list of all the posts tagged tag
would link to a list of all tags and under each tag would be all the posts tagged with that tag
While searching through Google yields a bunch of old plugins and some Liquid kludgery that can approximate this, (1) was most easily achieved by installing
jekyll-archives which can automatically generate pages for each tag as well as for each year and for each month.
I then added the following lines to
(This is also enables links to lists of posts by year—
http://mahiwaga.pw/*yyyy*/ and lists of posts by month—
I then created the file
This layout could probably use
a little a lot more work, but it will do for now.
Just as an aside, at least as of
jekyll-2.5.3, tags that are just numbers—
—will cause jekyll to crashout with non-obvious error messages.
Also, another thing I learned was that using tags with colons(:)—
—will get misinterpreted as YAML hashes.
Implementing (2) was a bit trickier.
It’s not too difficult to just iterate through all the tags to get to all the posts, but the tags are stored in the order of their occurrence, which seems quite haphazard and not that useful.
I did find a page explaining how to get a sorted list of tags using only Liquid, but ASCII sorting instead of alphabetically sorting still seemed rather messy.
(As an aside, I was highly amused by these rants regarding the fact that programming languages tend to always default to ASCII sorting and it’s rare to find a natively-implemented natural sorting function or subroutine, leading people to recurrently reinvent the wheel:
- Alphabetical != ASCIIbetical • 2007 Dec 11 • weblog.masukomi.org
- Sorting for Humans: Natural Sort Order • 2007 Dec 12 • Coding Horror
I laughed at this particular quote: “…what sane person would want ASCII order?”)
The specific issue is that the
sort Liquid filter implemented by Jekyll can only do an ASCII sort. While the master branch of Liquid has partially implemented a natural sort (really, it’s just a case-insensitive sort) I couldn’t figure out how to get Jekyll to use the
liquid-4.0.0.alpha gem and it kept pulling in
So I decided to implement this custom filter (adapted from Tanguy Krotoff):
I created the file
plugins/customfilter.rb which implements a Liquid filter named
Then I created
tag.md in the top level directory: