An overview of static site generators

and moving to Pelican

5 Jun '16

Using a static site generator (SSG) isn’t a new idea, but it’s a great idea. Security, ease of use, and future-proofing/avoiding lock-in are totally worth it. Hosting is dirt cheap. In 2016, there are an abundance of SSGs - I’d argue too many. But in 2013, when I first started thinking about this, there weren’t as many mature projects. So I made the situation worse by writing my own SSG using Flask and Frozen-Flask. And it works well, with not too many lines of code.

But for no particular reason, I decided to switch. I think it’s because I know that maintaining code is always underestimated. But which project to pick?

The most well-known SSG is Jekyll, and it’s well thought out. But there’s no way in hell I’m using Ruby; I hate almost everything about Ruby (but that’s for another post - all I’ll say now is that Ruby breaks between minor version numbers). So maybe something Python exists? IMO, SSGs don’t need to be fully featured, but should be hackable.

Finally, I found Pelican. Python 3, check. Jinja2 templates, check. Great API, check. The migration went well because I was already using a “Jekyll-compatible” markdown format. Attachments are a great way to manage files. The code-base is nice.

It isn’t completely perfect. Linking to other posts via the slug would be nice, and I’m sure easily doable. The periodic archive generation sucks because it uses the same template for year/month/day and the data that gets passed to those templates is also unstructured. But thanks to the API, I just wrote my own plugin to generate archives just as I want them, in about 50 lines of code.

There are other quirks. For me, attachments and other links in pages written in HTML weren’t being processed. To fix this, I replaced the overly-complicated default HTML reader with my own, that basically just reads the file. For some reason, this just works - so why doesn’t it out of the box? The build system is okay. The build scripts are terrible. Handling different settings via from x import * is horrible and hacky - expect a future blog post for a much better solution. Asset management is limited, it’s either webassets or nothing.

All of that aside, I’m very happy with Pelican, largely due to the hackability. Highly recommended for Pythoneers.

blog, Python, Flask

Newer Older