Moving from Pelican to Hugo
I was looking for a better theme for my blog which is based on Pelican static site generator in Python, but then I happened to look at this blog written in Hugo - a Go counterpart of Pelican. The thing which caught my eye was the posts page, which is exactly how I wanted my first page to be. I've always wanted something like Paul Graham's essays page, but couldn't find anything close to it until I found this site. After some thought, I decided to make the move. This move has no effect on my love for Python language. It's just laziness trumping drudgery :)
The good thing about static site generators is all of them support markdown – the markup language in which my Pelican blog was written. Althought the syntax of Hugo was different, I could scribble up a small Python script to convert Pelican's way of writing blog metadata to Hugo's.
Since I didn't want readers who saved my blog links as bookmarks to suffer, I
had to manually make sure that the URLs of blog posts are not changed. Hugo by
default uses the markdown file name as the URL name. Pelican by default
converts blog post title to a slug and uses that slug in the URL. This has
helped me have markdown file names in lexicographical order (first one named as
a-my-first-blog.md
, second one b-sequel-of-first-article.md
, and so
on) for chronological viewing. But now I have to either change the file names,
or write a slug
entry to each blog post's metadata. I figured out the earlier one
would be less time consuming, and did just that.
One problem I faced was, the site-generation script was throwing an error. Googling and stackoverflowing told me that it's due to Hugo version incompatibility. When Nate Finch, the original author of npf.io generated his site, he must have used an older version of Hugo. But I had only the latest Hugo binary, built from source. Within some time I was able to figure out the problem and fixed them, and then submitted pull request for the same too. Open source for the win :)
I also realized than whenever I create a new blog post using hugo new <filename>.md
, it would create another entry on the left sidebar, and not as a
blog post inside the ‘posts’ page. The workaround was easy here too: just move
the markdown file to blog
directory, and change a few variables as I've now
written in readme, and
it works as expected. I should probably write a shell function to do all of
these steps in one go :)
I had to ensure that I remove all files generated by Pelican, as otherwise one blog entry was going to the older-Pelican themed page when clicked on its link. This and a few tweaks later, I had my shiny blog ready :)