Jekyll has built-in support for tagging of pages and posts, but doesn’t provide any functionality to create tag clouds. Because this is so common, there is a nice plugin for it: jekyll-tagging.
When upgrading to Jekyll 3.3.1 I found that the plugin stopped working. So I decided to cook my own simple solution to get it to work. In this post I’ll shortly explain how I solved it.
For the proposed solutions to work, you will have to set a tag_dir variable in your _config.yml:
Tag Cloud for a Post
This is the simple one, you can see an example at the bottom of this post. In the post template (_layouts/post.html), you can add:
This simple loop lists the post tags and creates a link to the tag page (see below).
Tag Cloud for your entire Site
This creates a sorted collection of all tags used throughout your site and renders it in a list:
Generating a Tag Page for each tag
When users click a tag, they should see a list of pages that also use that tag (Tag Index). The snippet below creates those pages for you (based on the Category page generator example).
Make a new file _plugins/jekyll-tag-pages.rb:
We also need to provide the Tag Index with a view. The code above expects the view to be in _layouts/tag_index.html. To render the list, use this snippet:
That’s a wrap!
That should give you enough information to roll your own custom tag clouds. Feel free to get in touch if you have any questions or suggestions!