September 02, 2016

Quasi-automatic Tagging

Jekyll works really great with GitHub Pages but once you start playing around with plugins the realization quickly dawns that only a small subset is supported. Therefore, it’s easiest to use the safe: true option in “_config.yml” to ensure that when you view it locally it resembles what it will look like on GitHub Pages, because it disables custom plugins and ignores symbolic links.

After having tried several different tagging solutions (like Jekyll Tagging) before realizing the above incompatibility, I finally found an article about how to do it without needing any custom plugin.

It was actually really easy:

  1. The post layout was extended to detect if any tags are associated the current post, and links are generated to point to a new post_by_tag layout at /tag/THETAG/.

  2. For each tag used by posts, the following had to be added to _data/tags.yml:

     - slug: thetag
       name: The Proper Name of The Tag
    
  3. Finally, for each tag an empty template had to be created at tag/thetag.md containing:

     ---
     layout: post_by_tag
     tag: thetag
     permalink: /tag/thetag/
     ---
    

As you can see at the bottom of this post it says “Posted with: ..” with each of the tags associated the post. Clicking such a link takes one to the empty template file tag/thetag.md which uses the post_by_tag layout to display the information.

Whenever a new post is written two other files must be edited for each of the post’s tags, but it’s still a small price to pay for a working, quasi-automatic tagging system!

Posted with : GitHub Pages, Jekyll