2022-07-01 — 2 min read
Tagged: jekyll

Having Blog Posts Under a Custom Subdirectory

There are many ways we can customize the path a given blog post is under (which is called a permalink). Let’s see the details.

Without setting anything up, Jekyll will use the built-in date permalink style:

/:categories/:year/:month/:day/:title:output_ext

Since only posts and drafts have categories and dates, for pages and collections, the above is equivalent to

/:title.html

Jekyll lets us set the permalink format in multiple places, the later ones overriding the former settings:

Categories

As we can see in the default style, the path starts with the categories. We can set categories in two ways:

category: jekyll        # path: /jekyll/...
category: jekyll ruby   # path: /jekyll%20ruby/...
categories: jekyll ruby # path: /jekyll/ruby/...

We can also combine the two methods: if our post is at the above path, and also has the categories: jekyll ruby line in the front matter, its final categories will be notes tech jekyll ruby, and its default path will be ./notes/tech/jekyll/ruby/2022-02-22-my-post.html.

Setting a custom path for our blog

If we want to have every post under the /blog/ path, we can either set every post’s category to blog or, if we don’t want to use categories at all, we can set the global permalink style to /blog/:title or /blog/:pretty or any other variant we’d like.

Thanks for reading! If you have any comments, additions, or corrections, feel free to reach me via e-mail.

Copyright © 2023 csm.hu
Contact