Thursday, June 8, 2017

Moving from Blogger to Hugo

I really liked Blogger and I’ve hosted my blog on it since 2011. It was free (still is), but still had all the essentials features for a blog at the time and I like that it was integrated with Google.
My blogging needs haven’t changed since then but the world have evolved and Blogger no longer have all the essential features necessary for a blogging platform. Specifically, I’m talking about Blogger’s lack of support for SSL/TLS for custom domains. I could accept the dated editor controls, quirkiness in the WYSIWYG UI, and limited customization of themes, but there’s no excuse for not having https enabled on a web site anymore.
I’ve now moved Lazy Hacker Babble from Blogger to Hugo + Google App Engine. Hugo is a static site generator written in Go. It takes your markdown file and generates an entire web site consisting of static files so it doesn’t require databases runtimes, extra libraries, etc. Since it’s written in Go, Hugo comes as a stand-alone binary so there is no need to install a bunch of extra software in order to run it.

Static Hosting

There are a lot of free static page hosting services including Github pages and they also support custom domains. However, just like Blogger, custom domains don’t support HTTPS so I went with Google App Engine (GAE). GAE provides a free tier that supports more then my little blog will ever need, but it will auto-scale if I’m ever proven wrong. GAE also supports custom domains, but more importantly it supports HTTPS if you provide your own SSL/TLS certificate.
I wrote a post on how to use GAE with HTTPS for hosting static pages here.

Migrating

A big kudos to Blogger on how easy they made it to export data. Simply go to blog’s settings page and the whole blog can be downloaded as an XML file.
As a Go developer, I natually look for Go solutions and in this case I found blogimport which takes the Blogger XML file and generates a site of markdown files. I found it did a pretty good job converting from xml to Hugo files.
One glaring dislike I had for blogimport is that the main content of a blog post is kept as HTML. Blogger’s HTML is incredibly hard to read and edit so making changes in the future would be extremely tough.
Fortunately, there is a Go package that will convert HTML to markdown so I modified blogimport to apply the html2md filter to the post content before writing it to file.
Thinking I was done, I realize that Hugo was generating file names based on the post title so I needed up with multiple files that contains sequential periods in their name (e.g. abc....md which is not valid for GAE.
To change the title of over 50+ files that contained a sequence of periods, I used the following SED one-liner script:
sed -i "s/\(title = \".*\)\.\"/\1\"/g" *.md
Then I moved the resulting markdown files to the content/post directory of Hugo and used Hugo to generate a static files site.

Deploying

The final step is very simple. The details are written here.
In a nutshell, simply upload site pages to GAE and within minutes the site will be available.

3 comments:

  1. The link to the final step doesn't work. I'd love to get your modified version of bloggerimport.

    ReplyDelete
  2. Thanks! I've fixed the link. I'll see if I can dig up the bloggerimport script and maybe upload it to github.

    ReplyDelete
  3. Here's blogimport with my changes: https://github.com/lazyhacker/blogimport

    ReplyDelete