hakyll, shell
May 3, 2014

Creating well-behaved Hakyll blog posts

Posts in a Hakyll-powered blog need to be created with care, if you want your feed to work well with clients and aggregators. There are many things to remember:

I find this makes blogging feel tedious, especially after an absence when I’ve forgotten the details. Update: case in point, I managed to share an ugly template post with Planet Haskell readers while working on this one.

So I’m trying out this bash shell script, maybe it will help. Adjust to suit your setup.

# add to ~/.bashrc
# "blog SOME TITLE" creates a new hakyll-compatible draft blog post.
function blog() {
    AUTHOR="My Name"
    SLUG=${TITLE// /-}
    DATE=`date +"%Y-%m-%d"`
    TIME=`date +"%Y-%m-%d %H:%M:%S%Z"`
    cd $DIR
    echo creating $FILE
    cat <<EOF >>$FILE && emacsclient -n $FILE
title:     $TITLE
tags:      TAG1, TAG2
author:    $AUTHOR
published: $TIME


An example:

$ blog Scripted Hakyll blog post creation
creating _2014-05-03-Scripted-Hakyll-blog-post-creation.md
(file opens in emacs, edit & save)
$ make
./site build
  Creating store...
  Creating provider...
  Running rules...
Checking for out-of-date items
  updated blog/_2014-05-03-Scripted-Hakyll-blog-post-creation.md