Automatically Generating Tag Posts for GitHub Pages using Jekyll

Recently, I migrated my personal website from Wordpress to GitHub Pages using Jekyll. After some trial and error, I managed to have everything up and running. However, Jekyll tagging (i.e., generating the pages that contain a collection of posts filtered by a tag) requires additional plugins which are not supported by GitHub Pages. Long Qian wrote a fantastic tutorial on how to implement this functionality with a Python script. Unfortunately, this still requires running the script, adding the files to the staging area, committing them, and pushing them to GitHub. That’s a lot of steps for every time that I want to add a new tag. Not only is it prone to errors, but let’s be honest: ain’t nobody got time for that.

Therefore, I automated the whole process. I adapted Long’s solution and embedded it in a more comprehensive script, Now, I let GitPython handle the Git part (make sure you installed it beforehand). This way, after I finished updating/creating a post with new tags (and pushing those files to GitHub), I can run update_tags and let it do the rest: fish the tags used across all posts, create the corresponding posts, and commit and push these changes to GitHub in a single go. To keep things tidy, I recommend running this script when having a clean working space (nothing to commit/push).

Please note that Long’s original script reads the tags from posts that are formatted as follows:

layout: post
title: Jekyll Tags on Github Pages
description: Github Pages with Jekyll are cool!
tags: blog github-page jekyll

I adapted the script to read tags from posts that are formatted differently:

layout: post
title: Jekyll Tags on GitHub Pages
description: GitHub Pages with Jekyll are cool!
  - blog
  - github-page
  - jekyll

You can find all the files of my website in my GitHub repository.

If you have any comments, questions or feedback, leave them in the comments below or drop me a line on Twitter (@amoncadatorres). Moreover, if you found this useful, fun, or just want to show your appreciation, you can always buy me a cookie. Cheers!