Having moved my website from Wordpress to Poet recently, you’d think that a sane person would settle down and patiently blog for a while. And you’d be right, that’s exactly what a sane person would do.

In totally unrelated news, this website is now hosted on GitHub pages with the help of Jekyll-Bootstrap. Why, you ask? Well, as I wrote about previously, I’ve had some issues with Poet, and the creator sometimes takes a while to reply to raised issues or pull requests. Since I ran into two bugs and had to make two branches in order to simplify the pull request, I found it somewhat messy to bring up my blog with both fixes (yes, you create a third branch and rebase/merge the two PR branches, I know. Thank you very much for pointing it out). And then I came across Jekyll-Bootstrap, which effectively does the same thing that attracted me to Poet in the first place, which is the ability to create blog posts as markdown files inside Emacs and then painlessly publish them with a git push. So I decided to give it a go, and I liked it so much that I ended up migrating my whole blog to it.

The entire process was relatively painless, Poet uses a JSON-like frontmatter for its posts, while Jekyll-Bootstrap uses YAML. A single python script converted most of my posts with ease, after which it was a simple matter of cleaning up stuff here and there (most notably {% raw %} {{ {% endraw %} and {% raw %} }} {% endraw %} which are used for inline processing by the Liquid Templating language used by Jekyll).

Here’s the python code I used for migrating the posts:

from __future__ import print_function

import os
import json

for input_file in os.listdir("_oldposts"):
    fp = open("_oldposts/" + input_file, 'r')
    data = fp.read()
    fp.close()

    delim = data.find("}}}")
    if delim == -1:
        print("Unable to parse JSON front-matter" )
        break

    json_data = json.loads( data[2:delim+1] )
    old_date = json_data["date"].split("-")

    post_title = json_data["title"].replace(":", " -")
    post_date = old_date[2] + "-" + old_date[0] + "-" + old_date[1]
    post_filename = post_date + "-" + input_file
    post_content = data[delim+3:]
    post_tags = "[" + ", ".join(json_data["tags"]) + "]"

    fp = open("_posts/" + post_filename, 'w')

    print( "---", file=fp )
    print( "layout: post", file=fp )
    print( "title: " + post_title, file=fp )
    print( "tags: " + post_tags, file=fp )
    print( "---", file=fp )
    print( "{% include JB/setup %}", file=fp )

    print( post_content, file=fp )

    fp.close()