mirror of
https://github.com/theNewDynamic/gohugo-theme-ananke.git
synced 2025-06-08 09:12:47 +00:00
39 lines
1.3 KiB
HTML
39 lines
1.3 KiB
HTML
{{/*
|
|
GetFeaturedImage
|
|
|
|
This partial gets the featured image for a given page.
|
|
|
|
If a featured_image was set in the page's front matter, then that will be used.
|
|
|
|
If not set, this will search page resources to find an image that contains the word
|
|
"cover", and if found, returns the path to that resource.
|
|
|
|
If no featured_image was set, and there's no "cover" image in page resources, then
|
|
this partial returns false.
|
|
|
|
@return RelPermalink to featured image, or an empty string if not found.
|
|
|
|
*/}}
|
|
|
|
{{/* Declare a new variable, $coverImage */}}
|
|
{{ $coverImage := false }}
|
|
{{ $matches := "feature,cover" }}
|
|
{{/* Use the value from front matter if present */}}
|
|
{{ with .Params.featured_image }}
|
|
{{ $coverImage = . }}
|
|
{{/* If we find a Page Resource matching the exact value, we use it instead. */}}
|
|
{{ with $.Resources.GetMatch . }}
|
|
{{ $coverImage = . }}
|
|
{{ end }}
|
|
{{/* Find the first image with 'cover' in the name in this page bundle. */}}
|
|
{{ else }}
|
|
{{ with .Resources.ByType "image" }}
|
|
{{ with .GetMatch (printf "**{%s}*" $matches) }}
|
|
{{ $coverImage = . }}
|
|
{{ end }}
|
|
{{ end }}
|
|
{{ end }}
|
|
{{/* Return either an image or false. Note that partials can only have a single
|
|
return statement, so this needs to be at the end of the partial (and not in the if block) */}}
|
|
{{ return $coverImage }}
|