Updated image-related features
Fixed SVG support
Switched the site theme to hugo-theme-island , and then the build failed. The issue is, for image lazy loading, the theme fetch all cover images’ width and height, and wrote them into the img tag. However, rect.page has some cover images using SVG, so… boom.
The fix is to use reflect.IsImageResourceWithMeta to check if we can get dimensions:
Reports whether the given value is a Resource object representing an image from which Hugo can extract dimensions and, if present, Exif, IPTC, and XMP data.
Stop downloading remote images
While fixing the above issue, I noticed that remote images will be downloaded as well. This causes problems — every build would download all the cover images again. So I made a change: skip that, and allow users to specify width and height in cover. If not provided, width and height fall back to 750x500, then use object-fit: cover.
cover:
image: https://example/cover.png
width: 800
height: 400
alt: "demo image"
Fixed Markdown image rendering
Since I’m already here, might as well fix the render-image hook too. Previously, images in content would break when using a non-default language. While fixing this, I noticed all images were being treated as block-level, so I made a change using the render image’s .IsBlock to distinguish.
Auto-generate site icons
Also noticed the demo site had no favicon at all. So theme changed to read logo from config, and generate 32x32 and 16x16 icons, plus a 180x180 apple-touch-icon. Link tags are auto configurated. Hugo makes this really convenient:
{{- $logo := resources.GetMatch site.Params.logo -}}
{{- if reflect.IsImageResourceProcessable $logo -}}
{{- with $logo.Process "resize 180x png" -}}
<link rel="apple-touch-icon" sizes="180x180" href="{{ .RelPermalink }}">
{{- end -}}
{{- with $logo.Process "resize 32x png" -}}
<link rel="icon" type="image/png" sizes="32x32" href="{{ .RelPermalink }}" />
{{- end -}}
{{- with $logo.Process "resize 16x png" -}}
<link rel="icon" type="image/png" sizes="16x16" href="{{ .RelPermalink }}" />
{{- end -}}
{{- else if reflect.IsImageResourceWithMeta $logo -}}
<link rel="icon" type="image/png" sizes="{{ $logo.Width }}x{{ $logo.Height }}" href="{{ $logo.RelPermalink }}" />
{{- else if $logo -}}
<link rel="icon" type="image/png" href="{{ $logo.RelPermalink }}" />
{{- end -}}
Also, if favicon.ico or site.webmanifest exist under assets/, the corresponding link tags will be added automatically.
Updated template structure
Then Hugo kept WARNing about languageCode and languageName being deprecated, use locale and label instead. So I updated those too, and took the chance to update Hugo as well. Then I found out the tag detail pages were gone — term.html was still in _default… well, more precisely, both /tags/ and /tags/xxx/ now point to _default/taxonomy.html.
The reason is probably that Hugo performed a full re-implementation of how Go templates are handled in Hugo
, the template lookup order changed. The _default folder is deprecated, all files moved into layouts. Since I was already here, might as well do the migration — moved all files according to the new spec.
Then the archives page was gone — still related to the updated template system. In the old scenario, content/archives/_index.md would find _default/archives.html. But after the update, the lookup order became:
layouts/archives/section.htmllayouts/archives/list.htmllayouts/list.html
You can manually set layout: archives in archives/_index.md, but since theme users (if any) would likely be using the default config from the docs, I didn’t make that change. Instead, I moved layouts/archives.html to layouts/archives/section.html.
Also added a note in the docs that non-default language users need to specify type: archives instead of the previous layout: archives. Of course, keeping two copies of the same file is also an option, but that looks ugly.
By the way, if writing frontmatters, type is like telling it which folder to look for templates, and layout is telling it which template file to pick.
Updated language config
Lastly, new Hugo version replaced languageName and languageCode with label and locale , so I updated those as well.
Other
Document and demo site updated. Also made a new set of covers — pixel art scaled up to PNG, super small file size since it’s stored in indexed mode.