From f9ba6222e4278479a6eb221d644abdeca9dc4583 Mon Sep 17 00:00:00 2001 From: "C. Lente" <7017340+clente@users.noreply.github.com> Date: Sat, 4 Mar 2023 15:08:11 -0300 Subject: Dynamically generated social cards --- layouts/partials/seo_tags.html | 16 +++--- layouts/partials/social_card.html | 106 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 layouts/partials/social_card.html (limited to 'layouts') diff --git a/layouts/partials/seo_tags.html b/layouts/partials/seo_tags.html index 0b01f8b..84ab39e 100644 --- a/layouts/partials/seo_tags.html +++ b/layouts/partials/seo_tags.html @@ -3,11 +3,15 @@ - -{{ template "_internal/opengraph.html" . }} +{{ if (default false .Site.Params.generateSocialCard) }} + {{ partial "social_card.html" . }} +{{ else }} + + {{ template "_internal/opengraph.html" . }} - -{{ template "_internal/twitter_cards.html" . }} + + {{ template "_internal/twitter_cards.html" . }} - -{{ template "_internal/schema.html" . }} + + {{ template "_internal/schema.html" . }} +{{ end }} diff --git a/layouts/partials/social_card.html b/layouts/partials/social_card.html new file mode 100644 index 0000000..77bc251 --- /dev/null +++ b/layouts/partials/social_card.html @@ -0,0 +1,106 @@ + +{{ $font := resources.GetRemote "https://github.com/google/fonts/raw/main/ofl/firamono/FiraMono-Bold.ttf" }} +{{ $fg := resources.Get "/images/social_card_fg.png"}} +{{ $bg := resources.Get "/images/social_card_bg.png"}} + +{{ $fg = $fg.Filter (images.Text .Title (dict + "font" $font + "color" "#f8f8f2" + "size" 130 + "linespacing" 20 + "x" 0 + "y" 0 +)) }} + +{{ $date := .Date.Format (default "2006-01-02" .Site.Params.dateFormat) }} +{{ $byline := (printf "%s | %s" ($.Param "author") $date) }} + +{{ $fg = $fg.Filter (images.Text $byline (dict + "font" $font + "color" "#c9d1d9" + "size" 60 + "linespacing" 30 + "x" 0 + "y" 425 +)) }} + +{{ $card := $bg.Filter (images.Overlay $fg 112 140 ) }} +{{ $card := $card.Resize "900x webp q100" }} + + + + + + + + +{{- with .Params.images -}} +{{- range first 6 . }}{{ end -}} +{{- else -}} + +{{- end -}} + +{{- if .IsPage }} +{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}} + +{{ with .PublishDate }}{{ end }} +{{ with .Lastmod }}{{ end }} +{{- end -}} + +{{- with .Params.audio }}{{ end }} +{{- with .Params.locale }}{{ end }} +{{- with .Site.Params.title }}{{ end }} +{{- with .Params.videos }}{{- range . }} + +{{ end }}{{ end }} + +{{- /* If it is part of a series, link to related articles */}} +{{- $permalink := .Permalink }} +{{- $siteSeries := .Site.Taxonomies.series }} +{{- if $siteSeries }} +{{ with .Params.series }}{{- range $name := . }} + {{- $series := index $siteSeries ($name | urlize) }} + {{- range $page := first 6 $series.Pages }} + {{- if ne $page.Permalink $permalink }}{{ end }} + {{- end }} +{{ end }}{{ end }} +{{- end }} + +{{- /* Facebook Page Admin ID for Domain Insights */}} +{{- with .Site.Social.facebook_admin }}{{ end }} + + + +{{- with .Params.images -}} + + +{{ else -}} + + +{{- end }} + + +{{ with .Site.Social.twitter -}} + +{{ end -}} + + + + + + +{{- if .IsPage -}} +{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}} +{{ with .PublishDate }}{{ end}} +{{ with .Lastmod }}{{ end}} + + +{{- with .Params.images -}} +{{- range first 6 . -}}{{ end -}} +{{- else -}} + +{{- end -}} + + + +{{- end -}} -- cgit v1.2.3