summaryrefslogtreecommitdiffstats
path: root/tpl/tplimpl/embedded/templates/opengraph.html
diff options
context:
space:
mode:
authorMax Arnold <arnold.maxim@gmail.com>2019-11-27 02:11:53 +0700
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-11-26 20:11:53 +0100
commit25a6b33693992e8c6d9c35bc1e781ce3e2bca4be (patch)
tree106da0001c10753daa5ddb566ecf31eea778eb24 /tpl/tplimpl/embedded/templates/opengraph.html
parent01766439246add22a6e6d0c12f932610be55cd8a (diff)
tpl/tplimpl: Add support for featured and global image to OpenGraph template
Diffstat (limited to 'tpl/tplimpl/embedded/templates/opengraph.html')
-rw-r--r--tpl/tplimpl/embedded/templates/opengraph.html16
1 files changed, 12 insertions, 4 deletions
diff --git a/tpl/tplimpl/embedded/templates/opengraph.html b/tpl/tplimpl/embedded/templates/opengraph.html
index de2d2fddf..68b4de5a3 100644
--- a/tpl/tplimpl/embedded/templates/opengraph.html
+++ b/tpl/tplimpl/embedded/templates/opengraph.html
@@ -2,9 +2,18 @@
<meta property="og:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}" />
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}" />
<meta property="og:url" content="{{ .Permalink }}" />
-{{ with $.Param "images" }}{{ range first 6 . }}
+{{ with $.Params.images }}{{ range first 6 . -}}
<meta property="og:image" content="{{ . | absURL }}" />
-{{ end }}{{ end }}
+{{ 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 }}{{ end }}
{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
{{- if .IsPage }}
@@ -13,8 +22,7 @@
{{ end }}
{{- if not .Lastmod.IsZero }}<meta property="article:modified_time" {{ .Lastmod.Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end }}
{{- else }}
-{{- if not .Date.IsZero }}
-<meta property="og:updated_time" {{ .Date.Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />
+{{- if not .Date.IsZero }}<meta property="og:updated_time" {{ .Date.Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />
{{- end }}
{{- end }}{{/* .IsPage */}}