Skip to content

Commit

Permalink
feat: Twitter card support (#64)
Browse files Browse the repository at this point in the history
* feat: add `_internal/twitter_cards.html` template support

* use `with $.Params.images` logic directly
  • Loading branch information
thomasgtaylor authored Dec 26, 2021
1 parent 4c10fbd commit c52acfb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions layouts/partials/head/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@
<meta name="twitter:title" content="{{with.Title}}{{.}} | {{end}}{{.Site.Title}}" />
<meta name="application-name" content="{{with.Title}}{{.}} | {{end}}{{.Site.Title}}" />

{{- with $.Params.images -}}
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="{{ index . 0 | absURL }}"/>
{{ else -}}
{{- $images := $.Resources.ByType "image" -}}
{{- $featured := $images.GetMatch "*feature*" -}}
{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
{{- 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"/>
<meta name="twitter:image" content="{{ index . 0 | absURL }}"/>
{{ else -}}
<meta name="twitter:card" content="summary"/>
{{- end -}}
{{- end -}}
{{- end }}

<meta name="description" content="{{ if .Description }}{{.Description}}{{ else }}{{.Site.Params.siteDesc}}{{end}}" />
<meta name="twitter:description" content="{{ if .Description }}{{.Description}} {{ else }}{{.Site.Params.siteDesc}}{{end}}"/>
Expand Down

0 comments on commit c52acfb

Please sign in to comment.