bobatheme/layouts/partials/twitter_cards.html

30 lines
1008 B
HTML
Raw Normal View History

2021-11-20 18:24:56 -06:00
{{ $images := $.Resources.ByType "image" }}
{{ $featured := $images.GetMatch "*feature*" }}
{{ if not $featured }}
{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}
{{ end }}
{{ with $featured }}
{{ $ratio := 0 }}
{{ if gt .Width .Height }}
{{ $ratio = div (float .Width) .Height }}
{{ else }}
{{ $ratio = div (float .Height) .Width }}
{{ end }}
{{ if lt $ratio 1.75 }}
<meta name="twitter:card" content="summary_large_image">
{{ else }}
<meta name="twitter:card" content="summary">
{{ end }}
2021-11-20 18:24:56 -06:00
<meta name="twitter:image" content="{{ $featured.Permalink }}">
{{ end }}
<meta name="twitter:title" content="{{ .Title | plainify }}">
2021-11-20 18:24:56 -06:00
<meta name="twitter:description" content="{{ with .Description }}{{ . }}{{ else }}{{ if .IsPage }}{{ .Summary | plainify }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}">
{{ with .Site.Social.twitter }}
<meta name="twitter:site" content="@{{ . }}">
{{ end }}