|
123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <!-- From: https://gitlab.com/kaushalmodi/hugo-theme-refined/blob/b627ec997ad83e058b4cc817397fa1a3f0ce0b74/layouts/partials/twitter_cards.html
- via: https://discourse.gohugo.io/t/links-for-images-videos-audio-in-internal-templates-twitter-cards-and-opengraph/10464 -->
- {{ $permalink := .Permalink }}
- {{- with $.Params.images -}}
- <meta name="twitter:card" content="summary_large_image"/>
- <!-- As per https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/summary-card-with-large-image,
- the required card property is "twitter:image", not "twitter:image:src". -->
- {{- $image := (index . 0) -}}
- {{- $image_link_absolute := (findRE "^/" $image) -}}
- {{- if $image_link_absolute -}}
- <meta name="twitter:image" content="{{- $image | absURL -}}"/>
- {{- else -}}
- <meta name="twitter:image" content="{{- (printf "%s%s" $permalink $image) -}}"/>
- {{- end -}}
- {{ 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" content="{{ $featured.Permalink }}"/>
- {{- else -}}
- {{- with $.Site.Params.images -}}
- <meta name="twitter:card" content="summary_large_image"/>
- {{- $image := (index . 0) -}}
- {{- $image_link_absolute := (findRE "^/" $image) -}}
- {{- if $image_link_absolute -}}
- <meta name="twitter:image" content="{{- $image | absURL -}}"/>
- {{- else -}}
- <meta name="twitter:image" content="{{- (printf "%s%s" $permalink $image) -}}"/>
- {{- end -}}
- {{ 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 -}}
- <meta name="twitter:site" content="@{{ . }}"/>
- <meta name="twitter:creator" content="@{{ . }}"/>
- {{ end -}}
|