Cyrozap's Tech Projects

Computers. Circuits. Code.

Pelican is Wonderful

As I mentioned in my last post, Pelican is the tool I now use to generate all the static HTML files that make up this site. Pelican allows me to write posts using either Markdown or reStructuredText and can utilize a large variety of plugins written in Python. There are a number of blogging platform similar to Pelican like Octopress and Jekyll (upon which Octopress is based), but Pelican was the most fully-featured platform that is also written in a language I'm very comfortable with.

One of the benefits to writing posts as raw text files is that there is a plethora of utilities to edit text files on Linux/BSD/Darwin (and other *nix) platforms. For instance, I can use sed to do bulk replacements in posts, grep to search them, and I can use any combinantion of commands by combining them in a bash script. In fact, after importing my WordPress blog, I used this short script to organize the files in subdirectories based on their post date:

find ./posts -name "*.md" | xargs -n 1 \
python -c " \
import sys; \
path = sys.argv[1]; \
date_line = open(path,'r').read().split('\n')[1]; \
(year, month, day) = date_line.split()[1].split('-'); \
print 'mkdir -p ./posts/%s/%s; mv %s ./posts/%s/%s/%s' % \
(year, month, path, year, month, path.lstrip('./posts/'))" \
| sh

Ok, I guess it isn't that short and I probably could have done it all in Python, but it worked pretty well for me as a one-off command.

Pelican is very easily extensible. Right now, I'm using the pelican-octopress-theme as my blog theme. It's a nice theme, but I felt it was lacking some features. Thankfully, the template files are easy to modify so I was able to quickly change them to meet my needs. First, I changed how article URLs are generated on the Archives page. In the original version, the generated links were relative to the web path of the Archives page. With the default page "save as" and "URL" options, this is fine, but it doesn't work if you change them. To fix this, I prefixed the article.url variable with the SITEURL variable (among a few smaller changes). I also fixed the problem where the "Read On" button would display in the post index even if the article wasn't summarized. To do that, I just added a check to make sure the button was only displayed when the article.content didn't equal the article.summary. Finally, because I use FeedBurner, I added some FeedBurner integration. All I did was add an additional FEED_FEEDBURNER option to specify the FeedBurner URL and disable displaying the raw feed URLs on the page itself.

My changes were merged into the upstream pelican-octopress-theme repository as of commit bd5468f, so you can benefit from these new features, too!

Comments