Like most websites, mine initially had only one kind of content: a post. I liked the link-style posts that Daring Fireball uses so I mimicked that for my site. Sometimes I like to post a YouTube video and I could never remember the shortcode Hugo uses for that, so I create a third content type: videos. The latest posting type I have added are notes. These are short posts with no visible title on the main page.
Each of these different content types are referred to as archetypes by Hugo. Since my types grew organically over the course of years, they were not all created consistently. In fact, each of the first three (posts, links, videos) used a different mechanism to identify the post type. This made setting up the archive list and individual post pages cumbersome.
As a part of adding notes to the mix, I have refactored all the archetypes and set things up in a more Hugo idiomatic way.
Each of the four archetypes I have has a template Markdown file in the
archetypes directory. Each of these now have a common set of front matter
parameters:
Link posts have an additional parameter for the link URL. Video posts include a template for the YouTube shortcode. Having these templates makes creating new content much easier.
Having a type parameter for each archetype makes constructing the site
far simpler. The index.html layout can now easily include all four types, and
can set type specific icons. Handling the combination of link URL and post URL
for link posts is also controlled by the type parameter.
The single page layouts and list layout were also updated to make use of the
type parameter.
The code for iterating over all the content to create the archive page is less complicated and easier to modify. Cleaning up the archetypes was worthwhile.
Each content type has YAML front matter. With over 2300 posts on my site,
realigning them all to the same set of parameters, and eliminating no longer
necessary parameters, and correcting the type parameter, was no mean feat.
Some of that work was accomplished using find, grep, and sed commands.
Redoing the base parameters for every post was done via a Python script. The
script leaves the content alone, but reworks the front matter. I did this on a
copy of the content first, and only after all the wrinkles were ironed out, did
I run it for real. The
front_matter.py
script was created with help of AI.
I have temporarily hidden tags from the metadata show for each posting. My tags are a mess, both in how they are captured in the post’s front matter, and in the proliferation of different tag values. Cleaning that mess up is a project for another day.
All of these changes made for one of the largest (if not the largest) pull request I’ve ever created. Over 3000 files modified, with 49,909 lines added and 57,270 lines removed.
My site is better structured, hews more closely to the “Hugo way” of doing things, and it now has four posting types. I have wanted short note postings for some time, having that in place feels good.
I’ll run from the Git branch for a while, to make sure everything is working as expected. Once I’m sure nothing is broken, I’ll merge it into the main branch.