mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
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:
@@ -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 }}
|
||||
|
Reference in New Issue
Block a user