Files
George Cushen 76023f9461 refactor(images): adopt Hugo reflect.IsImageResource* API for type-safe image processing
Replace manual format detection (printf "%T", MediaType.SubType whitelists,
duck-typing) with Hugo's new reflect.IsResource, reflect.IsImageResource, and
reflect.IsImageResourceProcessable functions across 19 template files.

Key changes:
- process_responsive_image: collapse 15-line format whitelist into single
  reflect.IsImageResourceProcessable call
- Unify three-way SVG/processable/GIF branches into two-way $canProcess guard
- Remove duplicate GIF passthrough branches in single.html, events/page.html
- Add missing SVG guard in research-areas block (was calling .Fill unprotected)
- Replace nil checks with reflect.IsResource in get_cover_image/get_featured_image

Design decision: GIFs are intentionally excluded from processing despite Hugo
supporting it — processing strips animation frames, so we preserve user-optimized
animated GIFs by checking (IsImageResourceProcessable AND not GIF).
2026-03-27 04:35:53 +00:00

47 lines
1.7 KiB
HTML

{{/* HugoBlox function to retrieve the cover image */}}
{{/* Inputs: page context */}}
{{/* Output: image resource, or nil if not found */}}
{{/*
Cover image is searched in this order:
1. Search for a file `*cover*` in the page directory
2. Search for a file `.Params.cover.image` in the page directory
3. Search for a file `.Params.cover.image` in the `assets/media/` directory
*/}}
{{/* Search for an image "*cover*" in page folder */}}
{{ $resource := (.Resources.ByType "image").GetMatch "*cover*" }}
{{ if not (reflect.IsResource $resource) }}
{{/* Otherwise fall back to the image file specified in front matter */}}
{{ $filename := "" }}
{{ if .Params.cover }}
{{ if reflect.IsMap .Params.cover }}
{{ $filename = .Params.cover.image }}
{{ else }}
{{/* Support simple string format: cover: "image.jpg" */}}
{{ $filename = .Params.cover }}
{{ end }}
{{ end }}
{{ if $filename }}
{{/* Check if it's a remote URL */}}
{{ if or (strings.HasPrefix $filename "http://") (strings.HasPrefix $filename "https://") }}
{{ with resources.GetRemote $filename }}
{{ if reflect.IsResource . }}
{{ $resource = . }}
{{ else }}
{{ warnf "Remote cover image not found: %s" $filename }}
{{ end }}
{{ else }}
{{ warnf "Remote cover image not found: %s" $filename }}
{{ end }}
{{ else }}
{{/* Search in page folder */}}
{{ $resource = (.Resources.ByType "image").GetMatch $filename }}
{{/* Otherwise in `assets/media/` folder */}}
{{ if not (reflect.IsResource $resource) }} {{ $resource = resources.GetMatch (path.Join "media" $filename) }} {{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ return $resource }}