From bda54f97d8850884a17752951e5971ce2f8d58f1 Mon Sep 17 00:00:00 2001 From: Caio Lente <7017340+clente@users.noreply.github.com> Date: Thu, 4 Jan 2024 17:03:02 -0300 Subject: [PATCH] Update social card logic --- README.md | 2 +- exampleSite/config.toml | 2 +- layouts/_default/single.html | 2 +- layouts/partials/social_card.html | 44 ++++++++++++++++++++++++++----- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2d3be2e..d5b77dd 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,7 @@ enableRobotsTXT = true # Social media. Delete any item you aren't using to make sure it won't show up # in your website's metadata. - [social] + [params.social] email = "me@example.com" # Added to the footer so readers can reply to posts twitter = "example" # Twitter handle (without '@') facebook_admin = "0000000000" # Facebook Page Admin ID diff --git a/exampleSite/config.toml b/exampleSite/config.toml index d5eff2b..9e1f9c9 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -76,7 +76,7 @@ enableRobotsTXT = true # Social media. Delete any item you aren't using to make sure it won't show up # in your website's metadata. - [social] + [params.social] email = "me@example.com" # Added to the footer so readers can reply to posts twitter = "example" # Twitter handle (without '@') facebook_admin = "0000000000" # Facebook Page Admin ID diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 89b58d5..fb30bdf 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -16,7 +16,7 @@ #{{ .LinkTitle }}   {{ end }}

-{{ with .Site.Social.email }} +{{ with .Site.Params.social.email }}

{{ i18n "email-reply" }} ↪ diff --git a/layouts/partials/social_card.html b/layouts/partials/social_card.html index 68bb4ca..c55d56a 100644 --- a/layouts/partials/social_card.html +++ b/layouts/partials/social_card.html @@ -29,7 +29,7 @@ {{ $card := $card.Resize "900x webp q100" }} - + @@ -63,22 +63,52 @@ {{ end }}{{ end }} {{- end }} +{{- /* Deprecate site.Social.facebook_admin in favor of site.Params.social.facebook_admin */}} +{{- $facebookAdmin := "" }} +{{- with site.Params.social }} + {{- if reflect.IsMap . }} + {{- $facebookAdmin = .facebook_admin }} + {{- end }} +{{- else }} + {{- with site.Social.facebook_admin }} + {{- $facebookAdmin = . }} + {{- warnf "The social key in site configuration is deprecated. Use params.social.facebook_admin instead." }} + {{- end }} +{{- end }} + {{- /* Facebook Page Admin ID for Domain Insights */}} -{{- with .Site.Social.facebook_admin }}{{ end }} +{{ with $facebookAdmin }}{{ end }} - -{{ with .Site.Social.twitter -}} - -{{ end -}} + +{{- /* Deprecate site.Social.twitter in favor of site.Params.social.twitter */}} +{{- $twitterSite := "" }} +{{- with site.Params.social }} + {{- if reflect.IsMap . }} + {{- $twitterSite = .twitter }} + {{- end }} +{{- else }} + {{- with site.Social.twitter }} + {{- $twitterSite = . }} + {{- warnf "The social key in site configuration is deprecated. Use params.social.twitter instead." }} + {{- end }} +{{- end }} + +{{- with $twitterSite }} + {{- $content := . }} + {{- if not (strings.HasPrefix . "@") }} + {{- $content = printf "@%v" $twitterSite }} + {{- end }} + +{{- end }} - +