From 25a6b33693992e8c6d9c35bc1e781ce3e2bca4be Mon Sep 17 00:00:00 2001 From: Max Arnold Date: Wed, 27 Nov 2019 02:11:53 +0700 Subject: [PATCH] tpl/tplimpl: Add support for featured and global image to OpenGraph template --- tpl/tplimpl/embedded/templates.autogen.go | 18 +++++++++++++----- tpl/tplimpl/embedded/templates/opengraph.html | 16 ++++++++++++---- .../embedded/templates/twitter_cards.html | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/tpl/tplimpl/embedded/templates.autogen.go b/tpl/tplimpl/embedded/templates.autogen.go index 2bdb56b5b..fd8ecc381 100644 --- a/tpl/tplimpl/embedded/templates.autogen.go +++ b/tpl/tplimpl/embedded/templates.autogen.go @@ -185,9 +185,18 @@ if (!doNotTrack) { -{{ with $.Param "images" }}{{ range first 6 . }} +{{ with $.Params.images }}{{ range first 6 . -}} -{{ end }}{{ end }} +{{ end }}{{ else -}} +{{- $images := $.Resources.ByType "image" -}} +{{- $featured := $images.GetMatch "*feature*" -}} +{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} +{{- with $featured -}} + +{{ else -}} +{{- with $.Site.Params.images -}} + +{{ end }}{{ end }}{{ end }} {{- $iso8601 := "2006-01-02T15:04:05-07:00" -}} {{- if .IsPage }} @@ -196,8 +205,7 @@ if (!doNotTrack) { {{ end }} {{- if not .Lastmod.IsZero }}{{ end }} {{- else }} -{{- if not .Date.IsZero }} - +{{- if not .Date.IsZero }} {{- end }} {{- end }}{{/* .IsPage */}} @@ -509,7 +517,7 @@ if (!doNotTrack) { {{ else -}} {{- $images := $.Resources.ByType "image" -}} {{- $featured := $images.GetMatch "*feature*" -}} -{{- $featured := cond (ne $featured nil) $featured ($images.GetMatch "{*cover*,*thumbnail*}") -}} +{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} {{- with $featured -}} 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 @@ -{{ with $.Param "images" }}{{ range first 6 . }} +{{ with $.Params.images }}{{ range first 6 . -}} -{{ end }}{{ end }} +{{ end }}{{ else -}} +{{- $images := $.Resources.ByType "image" -}} +{{- $featured := $images.GetMatch "*feature*" -}} +{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} +{{- with $featured -}} + +{{ else -}} +{{- with $.Site.Params.images -}} + +{{ end }}{{ end }}{{ end }} {{- $iso8601 := "2006-01-02T15:04:05-07:00" -}} {{- if .IsPage }} @@ -13,8 +22,7 @@ {{ end }} {{- if not .Lastmod.IsZero }}{{ end }} {{- else }} -{{- if not .Date.IsZero }} - +{{- if not .Date.IsZero }} {{- end }} {{- end }}{{/* .IsPage */}} diff --git a/tpl/tplimpl/embedded/templates/twitter_cards.html b/tpl/tplimpl/embedded/templates/twitter_cards.html index fc4895b56..cbe2430bc 100644 --- a/tpl/tplimpl/embedded/templates/twitter_cards.html +++ b/tpl/tplimpl/embedded/templates/twitter_cards.html @@ -4,7 +4,7 @@ {{ else -}} {{- $images := $.Resources.ByType "image" -}} {{- $featured := $images.GetMatch "*feature*" -}} -{{- $featured := cond (ne $featured nil) $featured ($images.GetMatch "{*cover*,*thumbnail*}") -}} +{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} {{- with $featured -}}