Web

Some site updates February 2020

It’s been some time since I last rebuilt my site, and even longer since I’ve upgraded Hugo. Unsurprisingly, there’s been some maintenance to do. Here are some notes:

1) Some fixes to catch up with Hugo development

Hugo has gone through some breaking changes between 0.53 and 0.64. The ones that I’ve noticed so far on chrisnicoll.net are:

Changes to processing of shortcodes that broke my “Voluble/Terse” switch.

I use a shortcode to add the class name "voluble" to HTML elements generated from the Markdown between its opening and closing shortcodes. These elements can be hidden using CSS, depending on the state of the “Voluble/Terse” radio buttons at the top of the post. This stopped working on single paragraphs.

The cause was a change in Hugo 0.55, allowing shortcodes to work with footnotes and tables of contents. As I understand it, shortcodes with the {{% ... %}} syntax now ignore Markdown that’s wrapped in HTML elements within .Inner. Piping .Inner to markdownify fixes that (if desired), but there’s a side effect that’s still unresolved: according to @bep, “[t]he current logic is that we remove surrounding <p></p> if there is only one paragraph.”

(Aside: I had to look up how to show a Hugo shortcode on a Hugo site using @bep’s built-in syntax to treat its contents as a comment for the above paragraph.)

With the new behaviour, .Inner no longer has an element to add the "voluble" class to if there’s only one paragraph within.

There’s an open issue to deal with this; it seems to be a tricky problem. In the meantime, the provided workaround works: telling Hugo to use the old shortcode behaviour by adding the following to the start of the shortcode definition:

{{ $_hugo_config := `{ "version": 1 }` }}

Variables for accessing posts on the homepage

The change from .Pages .Site.RegularPages introduced in Hugo 0.57.0 broke the recent posts list on my homepage, giving me entries for tags and categories but not the latest posts.

The fix was to do a drop-in replacement of .Pages with .Site.RegularPages in my theme’s layouts/_default/index.html, to keep up with current variable names.

2) Adding a tag cloud

I had a lot of fun building a menu for my sidebar, then taking some features out of it, then moving some files around, and navigation is not as intuitive as I’d like it to be. I would guess that this site is most likely to be useful to somebody searching for a specific piece of practical information, and less likely to be browsed via internal navigation. However, while I work on structuring information, a nice tag cloud can’t hurt, right?

I dropped in tag cloud code by Artem Sidorenko, who credits Henrik Sommerfeld.