From 488da01892fccd6724723288e02fffc8220e5c73 Mon Sep 17 00:00:00 2001 From: "C. Lente" <7017340+clente@users.noreply.github.com> Date: Sat, 4 Mar 2023 16:36:06 -0300 Subject: Better social card logic --- README.md | 10 +++++++--- exampleSite/config.toml | 10 +++++++--- exampleSite/content.pt/_index.md | 1 - exampleSite/content.pt/blog/_index.md | 1 - exampleSite/content/_index.md | 1 - exampleSite/content/blog/_index.md | 1 - layouts/partials/seo_tags.html | 6 +++++- layouts/partials/social_card.html | 17 +++-------------- 8 files changed, 22 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index c45b176..85c662c 100644 --- a/README.md +++ b/README.md @@ -123,13 +123,17 @@ of the [demo](https://clente.github.io/hugo-bearcub/) for more information. # Basic config baseURL = "https://example.com" theme = "hugo-bearcub" -author = "John Doe" copyright = "John Doe (CC BY 4.0)" defaultContentLanguage = "en" # Generate a nice robots.txt for SEO enableRobotsTXT = true +# Your name. For more information on why this must be a list, see +# https://discourse.gohugo.io/t/site-author-usage/31459/8 +[author] + name = "John Doe" + # Setup syntax highlighting without inline styles. For more information about # why you'd want to avoid inline styles, see # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/style-src#unsafe_inline_styles @@ -189,9 +193,9 @@ enableRobotsTXT = true hideUntranslated = false # (EXPERIMENTAL) This theme is capable of dynamically generating social cards - # for posts that don't have `images` defined in their front matter. By setting + # for posts that don't have `images` defined in their front matter; By setting # `generateSocialCard` to false, you can prevent this behavior. For more - # information about images, see https://gohugo.io/functions/images/ + # information see layouts/partials/seo_tags.html generateSocialCard = true # Social media. Delete any item you aren't using to make sure it won't show up diff --git a/exampleSite/config.toml b/exampleSite/config.toml index 6dcaf75..cecd754 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -1,13 +1,17 @@ # Basic config baseURL = "https://example.com" theme = "hugo-bearcub" -author = "John Doe" copyright = "John Doe (CC BY 4.0)" defaultContentLanguage = "en" # Generate a nice robots.txt for SEO enableRobotsTXT = true +# Your name. For more information on why this must be a list, see +# https://discourse.gohugo.io/t/site-author-usage/31459/8 +[author] + name = "John Doe" + # Setup syntax highlighting without inline styles. For more information about # why you'd want to avoid inline styles, see # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/style-src#unsafe_inline_styles @@ -67,9 +71,9 @@ enableRobotsTXT = true hideUntranslated = false # (EXPERIMENTAL) This theme is capable of dynamically generating social cards - # for posts that don't have `images` defined in their front matter. By setting + # for posts that don't have `images` defined in their front matter; By setting # `generateSocialCard` to false, you can prevent this behavior. For more - # information about images, see https://gohugo.io/functions/images/ + # information see layouts/partials/seo_tags.html generateSocialCard = true # Social media. Delete any item you aren't using to make sure it won't show up diff --git a/exampleSite/content.pt/_index.md b/exampleSite/content.pt/_index.md index e22b426..4cf0d7e 100644 --- a/exampleSite/content.pt/_index.md +++ b/exampleSite/content.pt/_index.md @@ -1,7 +1,6 @@ --- title: "InĂ­cio" menu: "main" -images: ["/hugo-bearcub/images/share.webp"] weight: 1 --- diff --git a/exampleSite/content.pt/blog/_index.md b/exampleSite/content.pt/blog/_index.md index 7402287..7588ac1 100644 --- a/exampleSite/content.pt/blog/_index.md +++ b/exampleSite/content.pt/blog/_index.md @@ -1,6 +1,5 @@ --- title: "Blog" menu: "main" -images: ["images/share.webp"] weight: 2 --- \ No newline at end of file diff --git a/exampleSite/content/_index.md b/exampleSite/content/_index.md index fe7c802..10c388f 100644 --- a/exampleSite/content/_index.md +++ b/exampleSite/content/_index.md @@ -1,7 +1,6 @@ --- title: "Home" menu: "main" -images: ["/hugo-bearcub/images/share.webp"] weight: 1 --- diff --git a/exampleSite/content/blog/_index.md b/exampleSite/content/blog/_index.md index 7752b36..7588ac1 100644 --- a/exampleSite/content/blog/_index.md +++ b/exampleSite/content/blog/_index.md @@ -1,6 +1,5 @@ --- title: "Blog" menu: "main" -images: ["/hugo-bearcub/images/share.webp"] weight: 2 --- \ No newline at end of file diff --git a/layouts/partials/seo_tags.html b/layouts/partials/seo_tags.html index 84ab39e..81e498f 100644 --- a/layouts/partials/seo_tags.html +++ b/layouts/partials/seo_tags.html @@ -3,7 +3,11 @@ -{{ if (default false .Site.Params.generateSocialCard) }} + + + + +{{ if and (and (default false .Site.Params.generateSocialCard) (not (isset .Params "images"))) (eq .Kind "page") }} {{ partial "social_card.html" . }} {{ else }} diff --git a/layouts/partials/social_card.html b/layouts/partials/social_card.html index 77bc251..8bf397f 100644 --- a/layouts/partials/social_card.html +++ b/layouts/partials/social_card.html @@ -13,7 +13,8 @@ )) }} {{ $date := .Date.Format (default "2006-01-02" .Site.Params.dateFormat) }} -{{ $byline := (printf "%s | %s" ($.Param "author") $date) }} +{{ $author := (default $.Site.Author.name ($.Param "author") ) }} +{{ $byline := (printf "%s | %s" $author $date) }} {{ $fg = $fg.Filter (images.Text $byline (dict "font" $font @@ -34,11 +35,7 @@ -{{- with .Params.images -}} -{{- range first 6 . }}{{ end -}} -{{- else -}} -{{- end -}} {{- if .IsPage }} {{- $iso8601 := "2006-01-02T15:04:05-07:00" -}} @@ -71,13 +68,9 @@ -{{- with .Params.images -}} - - -{{ else -}} -{{- end }} + {{ with .Site.Social.twitter -}} @@ -95,11 +88,7 @@ {{ with .Lastmod }}{{ end}} -{{- with .Params.images -}} -{{- range first 6 . -}}{{ end -}} -{{- else -}} -{{- end -}} -- cgit v1.2.3