mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
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
This commit is contained in:
parent
df20b05463
commit
25d691daff
1 changed files with 14 additions and 1 deletions
|
@ -231,12 +231,25 @@ func (t *templateHandler) embedTemplates() {
|
|||
<!-- Facebook Page Admin ID for Domain Insights -->
|
||||
{{ with .Site.Social.facebook_admin }}<meta property="fb:admins" content="{{ . }}" />{{ end }}`)
|
||||
|
||||
t.addInternalTemplate("", "twitter_cards.html", `{{- with $.Param "images" -}}
|
||||
t.addInternalTemplate("", "twitter_cards.html", `{{- with $.Params.images -}}
|
||||
<meta name="twitter:card" content="summary_large_image"/>
|
||||
<meta name="twitter:image:src" content="{{ index . 0 | absURL }}"/>
|
||||
{{ else -}}
|
||||
{{- $images := $.Resources.ByType "image" -}}
|
||||
{{- $featured := $images.GetMatch "*feature*" -}}
|
||||
{{- $featured := cond (ne $featured nil) $featured ($images.GetMatch "{*cover*,*thumbnail*}") -}}
|
||||
{{- with $featured -}}
|
||||
<meta name="twitter:card" content="summary_large_image"/>
|
||||
<meta name="twitter:image:src" content="{{ $featured.Permalink }}"/>
|
||||
{{- else -}}
|
||||
{{- with $.Site.Params.images -}}
|
||||
<meta name="twitter:card" content="summary_large_image"/>
|
||||
<meta name="twitter:image:src" content="{{ index . 0 | absURL }}"/>
|
||||
{{ else -}}
|
||||
<meta name="twitter:card" content="summary"/>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end }}
|
||||
<meta name="twitter:title" content="{{ .Title }}"/>
|
||||
<meta name="twitter:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end -}}"/>
|
||||
{{ with .Site.Social.twitter -}}
|
||||
|
|
Loading…
Reference in a new issue