

Migrating this Blog to Hugo
source link: https://pointlessramblings.com/posts/migrating-this-blog-to-hugo/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Migrating this Blog to Hugo Wed 07 October 2020
This post marks the first release of this blog built using Hugo; hopefully nothing looks out of place! Hugo replaces my own Luapress that was in use since 2013. Hugo brings more functionality enabling me to do more interesting stuff without having to implement it myself. A blogroll, link summary posts or even a shit company rant section (another place to rant alongside Twitter). Back on topic, this post is about my experience rebuilding this blog using Hugo.
Everything is a Page
Hugo is well documented and has plenty of community support. It’s taken maybe 4 or 5 hours to do the migration. BUT - at the start I found some of the ways Hugo processes content to be confusing, and found little to no description of how this works. Let’s look at adding content in the quickstart example:
hugo new posts/my-first-post.md
hugo serve
… and just like that - a blog! OK, but Hugo builds all kinds of website, how’s the post appearing on the homepage? What happens if I make a /pages/info.md
? I did and… it appeared on the homepage as well - hmm.
Through much searching and browsing of example websites, I discovered that, quite simply, everything is a page. Blog posts are just pages. It’s the template that defines how, and more importantly which, pages are displayed. My mistake was thinking templates were simply a definition of look, like a WordPress template. Instead templates convey both look and function. That is to say that templates need to be content aware, and content needs to be template aware - the two go hand in hand. For example, to render only blog posts on the homepage, the homepage template would contain something similar to:
{{ range (where .Site.RegularPages "Section" "posts") }}
{{ .Render "post" }}
{{ end }}
OK, now we’re in business.
Building the Template
Now that I’d wrapped my head around the content <> template interaction, it was time to port over the “Pointless v10” template. Hugo uses Go’s builtin templating and it is awesome, a major step up from Mustache. The block based inheritence and general syntax is much like jinja2 or Django and so felt immediately familiar.
I skipped most of the documentation on themes and jumped right in starting with the Smol theme which seemed like a suitable bare-bones starting point. That, along with the blog example site and it only took an hour to do most of the conversion.
The only complex part was re-creating the masts list on the info page, which was previously generated via Luapress plugin (ie a Lua script):
{{ range $year := (sort (readDir "static/masts/home") "Name" "desc") }}
{{ range $month := (slice "December" "November" "October" "September" "August" "July" "June" "May" "April" "March" "February" "January") }}
{{ $filename := printf "masts/home/%s/%s.jpg" $year.Name $month }}
{{ if fileExists (printf "static/%s" $filename) }}
<img src="{{ $filename | relURL }}" />
{{ end }}
{{ end }}
{{ end }}
Permalink Changes
Finally the other hurdle to deal with was the permalinks! Luapress was generating links using underscores and no “slugification” of post titles. I much prefer Hugo’s slugified post URLs but needed to gracefully transition these over. I spent some time looking for an nginx solution until I discovered Hugo itself can handle this! All it takes is a simple alias flag in the old posts:
aliases:
- /posts/Why_Always_Docker/
Hugo and Beyond
That’s all there was to it - a smooth experience moving over to Hugo. Although I have no immediate changes planned, it’s now possible for me to modify and/or create content on this blog, my small slice of the internet.
Recommend
-
59
June 24, 2018 · 5 minutes to read · 920 words I recently migrated my personal website (the source code is on GitHub ) from
-
14
Finally I started migrating my personal blog gulu-dev.com into gitee.com, away from Bitcron, which I'm afraid is probably no longer a great choice for blog hosting, after writing 107 posts there for...
-
4
Posting regularly on blog: WordPress or hugo does the tooling matters? I have been running this blog since 2007 19 July 2007 to be precise, during this long timefram...
-
7
How it started When I decided to resurrect my personal blog a couple of months back I was pretty sure that I want something fast and small that won't require time to maintain. This narrowed down my choices to the static...
-
3
I just finished the last bits of migration for this site. It involved moving my podcasts from the podcast.sysca.st domain to a dedicated overview on this site. In this post, I’ve...
-
6
Blog migration to Hugo So I finally decided to bite the bullet and migrate from Wordpress to Hugo. I wanted to migrate out of Wordpress for a while but the a...
-
10
How to blog with ox-hugo in Emacs我的一篇老博客,介绍了用Emacs和Org-mode写博客的工作流。总的来说,勉强符合预期,流程稍显磕绊。今天偶然发现,用Org-mode写博...
-
10
How to set up a blog with Hugo and Cloudflare (and why you should) February 19, 2022 How to set up a blog with Hugo and Cloudflare (and why you should)...
-
6
Rename Hugo Blog Git Repo Branch From master To main 2021-03-05 :: 荒野無燈 :: Mod 2021-03-07(2270d09) #git March 7, 2021
-
10
在研究了一段时间hugo之后,我的blog也渐渐完善了些,现在该考虑一些有意思的插件了。 添加评论插件Disqus
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK