Select summary or summary_large_image in twitter card with image size

This commit is contained in:
BBaoVanC 2021-11-20 19:06:18 -06:00
parent a01a70fc91
commit d9776d29c4
Signed by: bbaovanc
GPG Key ID: 18089E4E3CCF1D3A

View File

@ -5,11 +5,23 @@
{{ end }}
{{ with $featured }}
<meta name="twitter:card" content="summary">
{{ $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 }}
<meta name="twitter:image" content="{{ $featured.Permalink }}">
{{ end }}
<meta name="twitter:title" content="{{ .Title }}">
<meta name="twitter:title" content="{{ .Title | plainify }}">
<meta name="twitter:description" content="{{ with .Description }}{{ . }}{{ else }}{{ if .IsPage }}{{ .Summary | plainify }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}">
{{ with .Site.Social.twitter }}