Overview
It’s nice to categorize your posts so you can browse related posts more easily.
- We use a plugin to generate category pages. The categories will be placed in
/categories/<category_name>. - We define
category_linksandcategory_linkfilters to create links to category pages.
Example
The list of categories for a post in the header above is generated like this:
{% if page.categories != empty %}
<p class="text-muted">Filed under {{ page.categories | category_links }} </p>
{% endif %}You can link to a single existing category page, for example,
<a href="{{ 'html' | category_link }}">HTML</a>will produce this link: HTML.
We can make a list of all categories like this:
<ul>
{% assign sorted_categories = site.categories | sort %}
{% for category in sorted_categories %}
<li><a href="{{ category | first | category_link}}">{{ category | first | capitalize}}</a></li>
{% endfor %}
</ul>Limitation
- Because we use Jekyll plugin, this doesn’t work automatically with Github Pages. You need to generate the site and push that to your
gh-pagesbranch instead. - Categories seem to be case-insensitive, so it might be hard to style them consistently.
- Categories with symbols might not work properly. Please modify the
slugify_categorymethod in_plugins/generate_categories.rbfor yourself.
