How to make an Archive of pages using categories in Jekyll
Why I make this?
On the Data for Education Systems website, I use the Just the Docs theme, which is great but also limiting as all off-the-shelf themes are.
I needed to create a page with a list of all the pages on the site displayed by categories. Jekyll has a built-in way of categorising posts but not pages. Here’s how I made it work.
Side note: I really think Hugo is a better static site generator than Jekyll. But then Jekyll walked, so Hugo could run.
What it look like?
Just go the Archive page on the D4ES site - https://data4edu.systems/archive/
How to do this?
This assumes that you have added categories to your pages. If you haven’t, you can do that by adding the following to the front matter of all the pages you want to display on the archive:
|
|
We will create two files:
- A new layout file for the archive page: this goes into the
_layouts
folder - A new page for the archive: this will likely be an
index.md
file in a folder calledarchive
in the root of your site
Here’s what the files will contain:
|
|
Update CATEGORYNAME1
and CATEGORYNAME2
in the <h3>
and <a>
tags above to the actual category names.
|
|
Note: This is not a scalable way of doing this because you have to manually create a new section for each category. I’m sure there’s a way to automate this but I haven’t figured it out yet.
I tried adding a list of categories in the site’s _config.yml
file and then looping through it using something like -
{% for category in site.categories %}
{{ category }}
{% endfor %}
But that didn’t work. I’ll update this post if I figure it out.