getting started with hugo

May 5, 2016   #hugo 

Some notes on renewing the blog …

Initial set up and migration

Creating a new site couldn’t be simpler (and yes, this isn’t blog-specific, you could really make any kind of static website)

$ hugo new site progblog

I came across this simple-to-use tool someone else created, called Octohug

Edit: I realized that the titles of the posts have been lost and replaced by the wordy urls, so “…” became “dot dot dot” and “/“ became “slash”. I might change this later, or I might be lazy and skip it. It’s not all that bad to look at anyway. Ditto for adding back tags/categories. Too bad.

Building and previewing the site

The counterpart to rake generate for Octopress, except much, much, much faster.

$ hugo --theme "angels-ladder" --buildDrafts

The counterpart to rake preview is something like:

$ hugo server -t angels-ladder -D -w

It’s worth pointing out that there is no longer any “generating files …” output on the console, because any changes are reflected within a second or so. Really, you can’t tell the difference (which, of course, is how it should be!)

Gist tags

A small digression: I had a lot of gist tags of the form {% gist 12f2347dfh9 %}, and I used these so often I began to think of them as part of standard markdown, but of course they’re not part of standard markdown, so we need a workaround, and luckily Hugo has a similar feature called shortcodes.

So, I added a shortcode layout for the gist keyword as described here, and then ran sed over the post content:

$ sed -i -- 's/{% gist \([0-9a-z]*\) %}/
/' content/post/*

Archiving the old blog

For nostalgic purposes (?) alone, I created a new repo, and saved a snapshot of the current agam.github.io repo there:

$ git push https://github.com/agam/Old-Jekyll-Blog.git
$ git push https://github.com/agam/Old-Jekyll-Blog.git master

Publishing to Github Pages

First of all, creating a new post is as simple as

$ hugo new post/getting-started-with-hugo.md

I briefly considered jumping to a different static hosting site, but it didn’t seem worth the trouble. So I adapted the approach described here, which just means cleaning up the existing repo, deleting the source branch, and directing Hugo’s output to the master branch, then pushing the same up to Github:

$ hugo -d ../Github/agam.github.io/ --theme=angels-ladder
$ cd ../Github/abam.github.io
$ git commit -a -m ‘sync to latest post’
$ git push origin master

That’s it! I do have some TODOs left, like installing Pygments so that source code formatting doesn’t suck , but other than that, I’m good to go.

Edit: No point leaving that hanging, so I added it:

<link rel="stylesheet" href="https://yandex.st/highlightjs/8.0/styles/default.min.css">
<script src="https://yandex.st/highlightjs/8.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

(I went with client-side highlighting since I didn’t want to slow down my fast new Go site generator with a sluggish Python plugin. So if the syntax coloring is off, you know whom to blame.)