Find and convert all Pelican tags to lowercase in Markdown text files

I published an article yesterday explaining how to use Apache rewrite rules to force lowercase tags and categories in Pelican 3.2 as it has a nasty bug of treating upper and lowercase tags and categories in articles separately.

I re-read the bug report and it looks like Pelican treats both upper and lowercase tags separately but the files it generates are all lowercase, meaning you’ll end up with a bunch of articles missing from a tag’s index page. Damn.

I got talking to Gabe Weatherhead of Macdrifter who has also been having the same trouble with Pelican as I have. He suggested it might be worth creating a script to convert all the tags to a lowercase format. It would be a better alternative than waiting an indefinite amount of time for Pelican 3.3 to be released.

Since Pelican’s release cycle is around 4 months (going off the last few versions) and I’m not quite ready to commit to running bleeding-edge software, I took his advice and created a quick one-line command to go through my previous articles and convert the tags to lowercase.

https://gist.github.com/jordanmerrick/5600220.js

This worked for me, but YMMV. The command will search through any .md in your current working directory, look for a line starting with tags: (case insensitive) and ending at the line break, then convert any text in-between to lowercase.

It’s quick, it’s hacky, there’s probably a better way to do it but it seems to work. I recommend copying your current articles (just a selection) to a temporary folder and testing it there, first. If it looks ok, go ahead and run it fully.

I tested this in OS X 10.8.3 as my articles are in Dropbox so I don’t need to run it on the server. It’s also destructive, it will edit files in place with no confirmation. Make sure to have a backup.