Two Wrongs

(don't make a right)

Statically Generated Blog

by ~kqr

As of a few hours ago, I have hopefully migrated this blog over from dynamic to static generation smoothly enough that nobody should notice.

Yesterday, when you visited one of the articles on this blog, the server gave a kick to a Haskell program, which went to a database, extracted the article content, and then rendered it in an HTML document for you. Now, when you refresh this page, the server just throws a pre-rendered HTML document at you.


When I set this blog up, I was torn. I really wanted to generate it statically (think Jekyll) because I've had a lot of success with that previously and it's a really convenient approach to blogging.

On the other hand, part of the reason I set the blog up was because I wanted to get some practise at dynamic generation of content. I wanted to learn Yesod which has powered the site for the year (almost) it's been up. When I started this blog a little more than a year ago, I had just gotten a Django web development job, so learning Yesod would be an interesting contrast to Django.

However, I don't have the time to dive deeply into things anymore. I wish I did, but there's a lot more going on in my life. So sadly, the site being powered by Yesod has held it back. Not because Yesod is bad – it's still the best web framework I've tried – but because I'm unfamiliar with it.

A friend of mine switched their blog over to static generation recently, which was the final push I needed.


The last couple nights I've been hammering out some Haskell code for parsing (easy! I've done that a million times before), file handling (slightly harder until I cheated and installed turtle to do the heavy lifting – turtle is amazing), and HTML generation (very hard because I've basically never done it in Haskell other than in a very small capacity.)

Anyway, creating stuff for this blog has become a lot easier. Previously I typed the posts up in Vim, copied them and pasted them over to the editor on the site, then clicked a bunch of buttons to jump between preview and editor until the post looked decent. Now I can just type in Vim, periodically run a command* and refresh my browser to see what it looks like. Much better.


Putting work into the technology underneath should be easier too. Things I've feared, like pagination, are just a couple of lines of Haskell away. Same thing with tags and other goodies I've been holding off of because I wouldn't know how to integrate them with Yesod in a good way.

The technology choices that went into this statically generating script/program might be interesting, and I hope to be able to write a bit more about that later. As I mentioned, I use turtle to manage files. I parse stuff with Attoparsec (my go-to parser combinator library these days) and I picked Heist for my templating needs. Heist brought me a lot of headache to start with, but I'm slowly understanding the concepts beneath it and I do like it after all.

Either way, I need to sleep … right now, would be good.

  1. * Though I gotta admit, I'm already imagining running the re-generation-program as a service that watches for changes to any files, and instantly re-generates whenever I save something …

Edit a day later: I have now created a tiny script that watches for changes in files with inotify-tools and then regenerates the blog whenever anything has changed. So convenient.

In fact, I'm editing this blog post in Vim right now, and as soon as I hit :w to save I can tab over to my web browser, refresh and I know it will be updated. Re-generating takes like a second at most, despite the fact that the program naively re-generates the entire blog when just one post has changed!

If you enjoyed this article, you might like others tagged with