Random thoughts shooting out of volatile mind
Tag Generation problem in Jekyll

After converting my blog to use Jekyll and hosting it on Github one problem I faced is missing tagging feature for post. I quickly came across this

I used plugin from the site and copied and modified some files from authors websites git repository. Only way to use tags on Github was to generate tags locally and move it to Github. To put more light on the point Github disables jekyll plugin so it won't generate the tags after you push your changes to Github repository. You need to follow these steps.

  1. Create posts
  2. Generate site locally by running jekyll
  3. Copy out _site/tag to your website root folder

I did this and it worked. But funny part was when I created new post and tagged it and followed above step for some reason tags won't reflect on respective tag's page and I had no clue why. After banging head for a while I noticed that Previously coped tag folder in site's root is overwriting the tags generated by Jekyll plugin!. Gosh so much for my stupidity :). Now I've written a script to generate tags after writing each new post. It deletes the existing tag directory first and then regenerates tag and copies it out to website root and then it commits the tag directory. Here it is

#!/bin/sh

TAG=tag/
SITE=_site/

if [ -d ${TAG} ]; then
    echo "Deleting ${TAG} directory..."
    rm -rf ${TAG}
fi

echo "Regenerating Site..."
jekyll

echo "Copying ${TAG} ..."
cp -a ${SITE}/${TAG} .

echo "Commiting Changes..."
git commit ${TAG} -m "Latest TAG build"

Hope that helps. Cya!

Posted by: copyninja on Tuesday, 13 March 2012

blog comments powered by Disqus
Fork me on GitHub