Fork me on GitHub

New Blog Platform

Like several others I've decided to switch my blog to a non-blog platform. I did this mainly because the whole blog platform web interface approach is not something that works well for me. Often when I think about writing something I want to focus on the writing and not on the whole process of creating a post. Instead, what usually happens is that I log into my blog platform see 1,400 spam comments, feel compelled to delete them all, and then give up on the whole idea. Dealing with media was always another hassle to deal with. In the end I knew I wanted to streamline the process.

Luckily, while I was rolling this around in my head others were doing the same thing. It turns out there's quite a few options out there in the Python world for using static blog generators to deliver up content. In the end I went with blogofile, but customized it a bit for my needs. With blogofile I'm able to write up a post in ReStructuredText format, commit it to Git, and push the repository to my server. From there a Git post-receive hook handles the process of rebuilding my blog. It's a simplified process that allows me to focus on writing content and not the process of getting a blog post out there.

One thing you'll notice is that my blog no longer has comment support. I'm on the fence on this one. Comments can often be helpful to further clarify, distill, or correct things that are written. But, dealing with spam is a hassle and not something I have the energy for. If I do enable comments it will be done by using Disqus as others have done. Until then, just contact me through twitter.

Converting My Content

One of the challenges when moving from one blog platform to another is getting your content converted. In my case I was going from HTML to ReStructuredText for the posts. I was also pulling data out of a PostgreSQL database. To simplify the process I wrote a script that uses SQLAlchemy and that made the process pretty straight forward. I've included an excerpt of the script below, but if you'd like the whole thing let me know.

def from_html_to_rst(content):
    p1 = Popen(["/Users/mtrier/.cabal/bin/pandoc",
                "--reference-links",
                "-r",
                "html",
                "-t",
                "rst"], stdin=PIPE, stdout=PIPE)
    p1.stdin.write(content)
    p1.stdin.close()
    return p1.stdout.read()

posts = session.query(Post).filter(Post.status==2).order_by(desc(Post.pub_date))

for post in posts:
    year_directory = os.path.join(post_directory, str(post.pub_date.year))
    mkdir_p(year_directory)
    with open("%s/%s-%s.rst" % (year_directory,
                                str(post.post_id).zfill(4),
                                post.slug.split('/')[-1]), 'w') as f:
        # write out YAML
        f.write('---\n')
        f.write("title: %s\n" % post.title)
        f.write("date: %s\n" % post.pub_date.strftime("%Y/%m/%d %H:%M:%S"))
        f.write("tags: %s\n" % ', '.join([p.name for p in post.tags]))
        f.write("categories: %s\n" % ', '.join([c.name for c in post.categories]))
        f.write("author: Michael Trier\n")
        f.write('---\n')
        try:
            f.write(from_html_to_rst(post.text))
        except Exception as e:
            print "Post %s can't be decoded." % post.post_id

To convert from HTML to ReStructuredText I used a Haskell tool called Pandoc. It worked quite well, requiring very little cleanup after the fact. Pandoc was easily installable on my Mac by using homebrew to bring in the Haskell platform and then using cabal to install Pandoc.

$ brew install haskell-platform
$ cabal update
$ cabal install pandoc

Hopefully all of these changes will mean that I'll be more inclined to post more often, but that remains to be seen. At least when I do post it will be a much simpler process. Special thanks to Mike Bayer for his help on some Blogofile issues.

You should follow me on Twitter.

blogroll

social