Hakyll 101
by Etienne Millon on November 21, 2011
So, the recent trend seems to be static blogging. Indeed, as a web application,
a blog is mostly read-only. By generating static .html
files, one can
eliminate :
- CPU load : static content is what’s easiest to serve, especially with modern servers using sendfile(2).
- security issues : without dynamic page generation, the attack surface is also vastly reduced. Authentication is moved from a PHP or Python script to the Unix way.
- deployment problems : I don’t know a free host that won’t serve static files. I use S3 (and the free tier will often be enough !) but if I am not satisfied, it’s dead simple to migrate.
Basically, it’s like moving from a dynamic language to a static one ☺. The only problem is if you want to add comments. The popular solution is Disqus but it is unfortunately a non-free application. I’ll probably stick to it but I fear data lock-in.
As it is fashionable, a lot of tools have appeared : pelican, blogofile, ikiwiki, jekyll… Being a haskeller, I decided to give hakyll a try.
Hakyll is a haskell library for writing and deploying static websites ; that’s about it. As in a dynamic application, you define routes and how to serve them :
makeCss :: Rules
=
makeCss $ match "css/*" $ do
void
route idRoute compile compressCssCompiler
Most rules consist of compiling markdown to HTML (with the fantastic pandoc library) and copying stuff around.
The resulting binary, when compiled, can be run to see previews, build files or even deploy the site.
~/www/blog [master] % ./blog
ABOUT
This is a Hakyll site generator program. You should always
run it from the project root directory.
USAGE
blog build Generate the site
blog clean Clean up and remove cache
blog help Show this message
blog preview [port] Run a server and autocompile
blog rebuild Clean up and build again
blog server [port] Run a local test server
blog deploy Upload/deploy your site
So far I’ve found it very easy to use. That’s it for this first mini-tour. Stay tuned !