2 minute read

Posts and categories

This post follows the previous Posts in Jekyll: 1. basics in this blog. The previous post showed how to set the key categories in the front matter of a post file:

layout: single
author_profile: true
itle:  "Posts in Jekyll: 1. basics"
excerpt: "How to set front matter in Jekyll posts and basic options for layout and content using the theme Minimal Mistakes."
date:   2024-09-20 12:13:03 +0200
last_modified_at:   2024-09-24 12:13:03 +0200
categories:
  - jekyllposts
tags:
  - jekyll
  - minimal mistakes

You do not need to set any category, but you can also set any number of categories you wish, e.g:

...
categories:
  - jekyllposts
  - mmistakes
...

Categories is a hierarchical way to group posts together. That it is a grouping mechanism is probably obvious. But that it is achieved by a hierarchy is not very clear. When a site is generated (bundle exec jekyll serve) the order of the categories determine the structure of the site. For example, the filename of this post is

YYYY-MM-DD-jekyll_posts02-categories.md

When generated as a static page, the html file (that is always named index.html) will be created in a sub-folder:

jekyll_posts02-categories/index.html

If your front matter does not define any categories (or permalink), the sub-folder will end up directly under the root:

./jekyll_posts02-categories/index.html

If you have a single categories defined (like for this very post), the sub-folder will end up in a folder named as this single categories:

./jekyllposts/jekyll_posts02-categories/index.html

If you have two (or more) categories listed in the front matter a complete hierarchy following the order of the categories will be generated. For the example above with two categories, the path (url) to the site html file will thus be:

./jekyllposts/mmistakes/jekyll_posts02-categories/index.html

Forcing a URL

If you want to customise the organisation of the urls of your posts you force the path under the root by setting the key permalink in the post front matter. The following permalink key:

permalink: /jekyllsposts/2_categories/

will force this file to the path:

./jekyllsposts/2_categories/index.html

For details on setting permalink in the _config.yml, please visit the Jekyll doc Permalinks.

Excluding a post from publication

You can exclude any individual post from being published with the site by setting the key published to false (not illustrated!):

published: false

Gather posts with same categories

You can use Jekyll’s extended Liquid language for gathering posts that share a categories item. The posts front page of this blog explains how this is done.

Resources

This blog - 1. basics

Jekyll - Permalinks

Liquid