Files
George Cushen 64cdb4a81a refactor(image): centralize page image params and warn on bad shape
Route all .Params.image access through a single normalizer partial that
returns the params as a map and emits a warnf with the expected shape
when frontmatter is set but not an object.
2026-05-27 03:53:21 +01:00

25 lines
1.1 KiB
HTML

{{/* Function to retrieve the featured image */}}
{{/* Inputs: page context */}}
{{/* Output: image resource, or nil if not found */}}
{{/*
Featured image is searched in this order:
1. Search for a file `*featured*` in the page directory
2. Search for a file `.Params.image.filename` in the page directory
3. Search for a file `.Params.image.filename` in the `assets/media/` directory
*/}}
{{/* Search for an image "*featured*" in page folder */}}
{{ $resource := (.Resources.ByType "image").GetMatch "*featured*" }}
{{ if not (reflect.IsResource $resource) }}
{{/* Otherwise fall back the image file specified in front matter */}}
{{ $image_params := partial "functions/get_page_image_params.html" . }}
{{ $filename := $image_params.filename | default "" }}
{{/* 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 }}
{{ return $resource }}