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.
- Jekyll: Ruby - nope
- Hugo: It’s GoLang, it’s fast… I’d rather have simple
- Cactus: Django templates instead of Jinja2
- Hyde: No Python 3 support? Are you serious?
- Nikola: Way to complicated, even though they claim simplicity. Just look at the files in the repo. PHP support - wat? (However, the build system looks seriously good)
- Lektor: I generally love anything Armin Ronacher does, but Lektor seems to be focussed more on the content management aspect with an admin interface
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.