mirror of
https://github.com/adityatelange/hugo-PaperMod.git
synced 2024-12-28 23:53:20 -05:00
df330a05b5
for `opengraph`, `schema` and `twitter_cards` templates
The page images selection order as follows:
1. Page's images parameter, image resources are supported.
2. Page's image resources that naming in *feature*, *cover* or *thumbnail* pattern.
3. If no page images specified, then the first one of site's images will be used as the fallback, supports site resources.
cherry-picked from 14d85ec136
++ compatibility fixes for PaperMod
Co-authored-by: Aditya Telange <21258296+adityatelange@users.noreply.github.com>
48 lines
1.4 KiB
HTML
48 lines
1.4 KiB
HTML
{{- $imgs := slice }}
|
|
{{- $imgParams := .Params.images }}
|
|
{{- $resources := .Resources.ByType "image" -}}
|
|
{{/* Find featured image resources if the images parameter is empty. */}}
|
|
{{- if not $imgParams }}
|
|
{{- $featured := $resources.GetMatch "*feature*" -}}
|
|
{{- if not $featured }}{{ $featured = $resources.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
|
|
{{- with $featured }}
|
|
{{- $imgs = $imgs | append (dict
|
|
"Image" .
|
|
"RelPermalink" .RelPermalink
|
|
"Permalink" .Permalink) }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{/* Use the first one of site images as the fallback. */}}
|
|
{{- if and (not $imgParams) (not $imgs) }}
|
|
{{- with site.Params.images }}
|
|
{{- $imgParams = first 1 . }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{/* Parse page's images parameter. */}}
|
|
{{- range $imgParams }}
|
|
{{- $img := . }}
|
|
{{- $url := urls.Parse $img }}
|
|
{{- if eq $url.Scheme "" }}
|
|
{{/* Internal image. */}}
|
|
{{- with $resources.GetMatch $img -}}
|
|
{{/* Image resource. */}}
|
|
{{- $imgs = $imgs | append (dict
|
|
"Image" .
|
|
"RelPermalink" .RelPermalink
|
|
"Permalink" .Permalink) }}
|
|
{{- else }}
|
|
{{- $imgs = $imgs | append (dict
|
|
"RelPermalink" (relURL $img)
|
|
"Permalink" (absURL $img)
|
|
) }}
|
|
{{- end }}
|
|
{{- else }}
|
|
{{/* External image */}}
|
|
{{- $imgs = $imgs | append (dict
|
|
"RelPermalink" $img
|
|
"Permalink" $img
|
|
) }}
|
|
{{- end }}
|
|
{{- end }}
|
|
{{- return $imgs }}
|