Loading...

Permalinks in Jekyll

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

Used:   jekyll 4.2.2 

Jekyll is a static site generator. It takes text written in your favorite markup language and uses layouts to create a static website. You can tweak the site’s look and feel, URLs, the data displayed on the page, and more.

I reorganized a long time ago my notes in collections and changed in the _config.yml (Jekyll configuration) this permalink.

collections:
  cinhtau:
    output: true
    permalink: /:collection/:name

Strangely, my generated links stop working.

<ul>

  <li><a href="/cinhtau/categories/">Categories and Tags</a></li>   

  <li><a href="/cinhtau/code/">Code Highlighting</a></li>   

  <li><a href="/cinhtau/emojis/">Emojis</a></li>   

  <li><a href="/cinhtau/font-awesome/">Font Awesome 5 Integration</a></li>   

  <li><a href="/cinhtau/keyboard/">Keyboard Styling</a></li>   

  <li><a href="/cinhtau/liquid/">Liquid</a></li>   

  <li><a href="/cinhtau/toc/">TOC</a></li>   

</ul>

Inspecting docs and output:

tan@omega:~/docs$ ls -l _site/cinhtau/
total 248
-rw-rw-r-- 1 tan tan   8420 Apr 27 15:43 categories.html
-rw-rw-r-- 1 tan tan  12173 Apr 27 15:43 code.html
-rw-rw-r-- 1 tan tan 177156 Apr 27 15:43 emojis.html
-rw-rw-r-- 1 tan tan  11465 Apr 27 15:43 font-awesome.html
-rw-rw-r-- 1 tan tan   7469 Apr 27 15:43 index.html
-rw-rw-r-- 1 tan tan   7230 Apr 27 15:43 keyboard.html
-rw-rw-r-- 1 tan tan   7152 Apr 27 15:43 liquid.html
-rw-rw-r-- 1 tan tan   8451 Apr 27 15:43 toc.html

Turns out if you miss the trailing slash (/), Jekyll use the source file name only. Adding the trailing slash to the configuration.

collections:
  pages:
    output: true
    permalink: /:collection/:name/

With trailing slash the directory will be created and a index.html.

tan@omega:~/docs$  ls -l _site/cinhtau/
total 36
drwxrwxr-x 2 tan tan 4096 Apr 27 15:48 categories
drwxrwxr-x 2 tan tan 4096 Apr 27 15:48 code
drwxrwxr-x 2 tan tan 4096 Apr 27 15:48 emojis
drwxrwxr-x 2 tan tan 4096 Apr 27 15:48 font-awesome
-rw-rw-r-- 1 tan tan 7476 Apr 27 15:48 index.html
drwxrwxr-x 2 tan tan 4096 Apr 27 15:48 keyboard
drwxrwxr-x 2 tan tan 4096 Apr 27 15:48 liquid
drwxrwxr-x 2 tan tan 4096 Apr 27 15:48 toc

tan@omega:~/docs$ ls -l _site/cinhtau/categories/
total 12
-rw-rw-r-- 1 tan tan 8422 Apr 27 15:48 index.html

And links are fully functioning again.

Please remember the terms for blog comments.