Overview
Like in this small blog, usually you will want to organize together posts with similar contents in categories or tags.
What I wanted to do is assign a color to each category in a Jekyll project.
For that, I’ve created in the root directory a _categories
directory where each category is going to be stored as a HTML (markdown) file.
The code of a category _categories/jekyll.html
could be the following:
In this post _post/2017-11-20-jekyll-color-code-categories
we’ll add a list of categories:
We also need to add a ‘categories’ collection in the config file ./_config.yml
:
For displaying the category in a post or in the home page, the snippet that I came up with is the following (probably a better solution could be thought up):
Was hard to escape liquid template tags like
{% xxx %)
while writing this post; I found a clean solution for this problem without using any plug-ins in: https://stackoverflow.com/questions/3426182/how-to-escape-liquid-template-tags
The output of this solution is the one you can visualize in the blog.