You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

49 lines
1.5 KiB

{{/*
GetHeaderImage
This partial gets the resource for the header image for a given page.
If a header_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 header_image was set, and there's no "cover" image in page resources, then
this partial returns an empty string (which evaluates to false).
@return Resource of header image, or an empty string if not found.
*/}}
{{ $headerImage := "" }}
{{/* Defined as params */}}
{{ if isset .context.Params .name }}
{{ $image_name := .context.Param .name }}
{{ with .context.Resources.GetMatch $image_name }}
{{ $headerImage = . }}
{{ end }}
{{ end }}
{{/* Defined as resource */}}
{{ if $headerImage }}
{{ else }}
{{ if .context.Resources.GetMatch .name }}
{{ $img := .context.Resources.GetMatch .name }}
{{ with $img }}
{{ $headerImage = . }}
{{ end }}
{{/* Find the first image with 'cover' in the name in this page bundle. */}}
{{ else }}
{{ $img := (.context.Resources.ByType "image").GetMatch "*cover*" }}
{{ with $img }}
{{ $headerImage = . }}
{{ end }}
{{ end }}
{{ end }}
{{/* return either a Resource, or an empty string. 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 $headerImage }}