From: Bjørn Erik Pedersen Date: Mon, 29 Jan 2018 10:44:41 +0000 (+0100) Subject: tpl: Update Twitter card to also consider images in .Resources X-Git-Tag: v0.35~16 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=25d691daff57d7c6d7d0f63af3991d22e3f788fe;p=brevno-suite%2Fhugo tpl: Update Twitter card to also consider images in .Resources The new lookup order: 1) Page.Params.images if set 2) Image resources: images with name "feature" (priority), "cover", "thumbnail" 3) Site.Params.images if set Fixes #4349 --- diff --git a/tpl/tplimpl/template_embedded.go b/tpl/tplimpl/template_embedded.go index 0b42da7c..b54a4bbe 100644 --- a/tpl/tplimpl/template_embedded.go +++ b/tpl/tplimpl/template_embedded.go @@ -231,12 +231,25 @@ func (t *templateHandler) embedTemplates() { {{ with .Site.Social.facebook_admin }}{{ end }}`) - t.addInternalTemplate("", "twitter_cards.html", `{{- with $.Param "images" -}} + t.addInternalTemplate("", "twitter_cards.html", `{{- with $.Params.images -}} + + +{{ else -}} +{{- $images := $.Resources.ByType "image" -}} +{{- $featured := $images.GetMatch "*feature*" -}} +{{- $featured := cond (ne $featured nil) $featured ($images.GetMatch "{*cover*,*thumbnail*}") -}} +{{- with $featured -}} + + +{{- else -}} +{{- with $.Site.Params.images -}} {{ else -}} {{- end -}} +{{- end -}} +{{- end }} {{ with .Site.Social.twitter -}}