Billy Fung

Porting to Hugo

Billy Fung / 2018-01-08


Learning Go by porting my website to Hugo

Scaffolding

One of the first things I look at in a framework is scaffolding. Akin to visiting a new city, the infrastructure shows how everything is laid out and the ease of access. As a city grows, the infrastructure also gets more complex. With most problems, I approach from a first principles viewpoint, start as small as I can, and then add to the problem sample as requirements are found.

Hugo starts with folders for archetypes, content, data, layouts, public, static, and themes. The configuration, or instructions for the scaffolding, lies within the config.toml file.

One of the first things that I did was write a list of features that I’d like to have for the blog engine. - code syntax formatting - math formatting and support - colour coded code blocks if possible - automated frontmatter creation for blog posts - simple markdown structure

Moving stuff over

One of the first things to move over was structure of how figures/images were placed in my middleman blog.

find . -name "*.png" -exec mv {} figures \;

Then I grab all the blog post content, dump into a single file reformat that single file into multiple files for hugo.

find . -name "*.html" -exec html2text {} --mark-code --reference-links  > index.md \; > index.md

This part made me a bit sad, knowing that the creator of such a beautiful tool, html2text, was no longer with us. Prosecuted for doing what he believed in, and what he loved.