tpl: Allow using page resources on the images page parameter 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.
This commit is contained in:
Razon Yang
2023-12-04 19:05:41 +08:00
committed by GitHub
parent 171836cdfa
commit 14d85ec136
6 changed files with 75 additions and 51 deletions

View File

@@ -3,17 +3,9 @@
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}" />
<meta property="og:url" content="{{ .Permalink }}" />
{{- with $.Params.images -}}
{{- range first 6 . }}<meta property="og:image" content="{{ . | absURL }}" />{{ end -}}
{{- else -}}
{{- $images := $.Resources.ByType "image" -}}
{{- $featured := $images.GetMatch "*feature*" -}}
{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
{{- with $featured -}}
<meta property="og:image" content="{{ $featured.Permalink }}"/>
{{- else -}}
{{- with $.Site.Params.images }}<meta property="og:image" content="{{ index . 0 | absURL }}"/>{{ end -}}
{{- end -}}
{{- $images := partial "_funcs/get-page-images" . -}}
{{- range first 6 $images -}}
<meta property="og:image" content="{{ .Permalink }}" />
{{- end -}}
{{- if .IsPage }}