mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-12 14:14:48 +00:00
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.
25 lines
1.1 KiB
HTML
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 }}
|