From 490e51b72f0d7590557195377681cd96ad31f908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Wed, 11 Oct 2023 17:31:27 +0200 Subject: [PATCH] theme: write own social implementation #683 to fix titles --- exampleSite/config/_default/config.toml | 2 +- layouts/partials/meta.html | 3 +- layouts/partials/opengraph.html | 109 ++++++++++++++++++++++++ layouts/partials/social.html | 2 - layouts/partials/twitter_cards.html | 48 +++++++++++ 5 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 layouts/partials/opengraph.html delete mode 100644 layouts/partials/social.html create mode 100644 layouts/partials/twitter_cards.html diff --git a/exampleSite/config/_default/config.toml b/exampleSite/config/_default/config.toml index 0890b88285..fb68cc15bc 100644 --- a/exampleSite/config/_default/config.toml +++ b/exampleSite/config/_default/config.toml @@ -34,7 +34,7 @@ defaultContentLanguage = "en" # disableLanguages = ['pir'] # the site's title of this showcase; you should change this ;-) -title = "Hugo Relearn Documentation" +title = "Hugo Relearn Theme" [outputs] # add JSON to the home to support Lunr search; This is a mandatory setting diff --git a/layouts/partials/meta.html b/layouts/partials/meta.html index de45332fda..9df35b64cf 100644 --- a/layouts/partials/meta.html +++ b/layouts/partials/meta.html @@ -17,4 +17,5 @@ {{- with .Site.Params.author }} {{- end }} -{{ partial "indent.html" (dict "content" (partial "social.html" .) "indention" " ") }} \ No newline at end of file + {{- partial "opengraph.html" . }} + {{- partial "twitter_cards.html" . }} \ No newline at end of file diff --git a/layouts/partials/opengraph.html b/layouts/partials/opengraph.html new file mode 100644 index 0000000000..f49806d149 --- /dev/null +++ b/layouts/partials/opengraph.html @@ -0,0 +1,109 @@ +{{- /* based on Hugo 0.119.0 _internal/opengraph.html but with modified title */}} +{{- $format := partial "get-format.hugo" . }} +{{- $outputFormat := partial "output-format.hugo" (dict "page" . "format" $format) }} +{{- $page := . }} +{{- $title := .Title }} +{{- if eq $outputFormat "searchpage" }} + {{- $title = T "Search" }} +{{- else if eq .Kind "taxonomy" }} + {{- $title = i18n .Data.Plural }} + {{- if not $title }} + {{- $title = .Data.Plural }} + {{- end }} +{{- else if eq .Kind "term" }} + {{- $title = i18n .Data.Singular }} + {{- if not $title }} + {{- $title = .Data.Singular }} + {{- end }} + {{- $title = printf "%s %s %s" .Title (default "::" .Site.Params.titleSeparator) $title }} +{{- end }} +{{- if and $title .Site.Title (not (eq $title .Site.Title)) }} + {{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) .Site.Title }} +{{- end }} + + + + +{{- with $.Params.images }} + {{- range first 6 . }} + + {{- end }} +{{- else }} + {{- $images := $.Resources.ByType "image" }} + {{- $featured := $images.GetMatch "*feature*" }} + {{- if not $featured }} + {{- $featured = $images.GetMatch "{*cover*,*thumbnail*}" }} + {{- end }} + {{- with $featured }} + + {{- else }} + {{- with $.Site.Params.images }} + + {{- end }} + {{- end }} +{{- end }} +{{- if .IsPage }} + {{- $iso8601 := "2006-01-02T15:04:05-07:00" }} + {{- with .Parent }} + {{- $page := . }} + {{- $link := "" }} + {{- $title := .Title }} + {{- if eq $outputFormat "searchpage" }} + {{- $title = T "Search" }} + {{- else if eq .Kind "taxonomy" }} + {{- $title = i18n .Data.Plural }} + {{- if not $title }} + {{- $title = .Data.Plural }} + {{- end }} + {{- else if eq .Kind "term" }} + {{- $title = i18n .Data.Singular }} + {{- if not $title }} + {{- $title = .Data.Singular }} + {{- end }} + {{- $title = printf "%s %s %s" .Title (default "::" .Site.Params.titleSeparator) $title }} + {{- end }} + {{- if and $title .Site.Title (not (eq $title .Site.Title)) }} + {{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) .Site.Title }} + {{- end }} + + {{- end }} + {{- with .PublishDate }} + + {{- end }} + {{- with .Lastmod }} + + {{- end }} +{{- end }} +{{- with .Params.audio }} + +{{- end }} +{{- with .Params.locale }} + +{{- end }} +{{- with .Site.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 }} \ No newline at end of file diff --git a/layouts/partials/social.html b/layouts/partials/social.html deleted file mode 100644 index d8204e65aa..0000000000 --- a/layouts/partials/social.html +++ /dev/null @@ -1,2 +0,0 @@ -{{- template "_internal/opengraph.html" . }} -{{- template "_internal/twitter_cards.html" . }} \ No newline at end of file diff --git a/layouts/partials/twitter_cards.html b/layouts/partials/twitter_cards.html new file mode 100644 index 0000000000..2d3266ce33 --- /dev/null +++ b/layouts/partials/twitter_cards.html @@ -0,0 +1,48 @@ +{{- /* based on Hugo 0.119.0 _internal/twitter_cardss.html but with modified title */}} +{{- $format := partial "get-format.hugo" . }} +{{- $outputFormat := partial "output-format.hugo" (dict "page" . "format" $format) }} +{{- $page := . }} +{{- $title := .Title }} +{{- if eq $outputFormat "searchpage" }} + {{- $title = T "Search" }} +{{- else if eq .Kind "taxonomy" }} + {{- $title = i18n .Data.Plural }} + {{- if not $title }} + {{- $title = .Data.Plural }} + {{- end }} +{{- else if eq .Kind "term" }} + {{- $title = i18n .Data.Singular }} + {{- if not $title }} + {{- $title = .Data.Singular }} + {{- end }} + {{- $title = printf "%s %s %s" .Title (default "::" .Site.Params.titleSeparator) $title }} +{{- end }} +{{- if and $title .Site.Title (not (eq $title .Site.Title)) }} + {{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) .Site.Title }} +{{- end }} +{{- with $.Params.images }} + + +{{- else }} + {{- $images := $.Resources.ByType "image" }} + {{- $featured := $images.GetMatch "*feature*" }} + {{- if not $featured }} + {{- $featured = $images.GetMatch "{*cover*,*thumbnail*}" }} + {{- end }} + {{- with $featured }} + + + {{- else }} + {{- with $.Site.Params.images }} + + + {{- else }} + + {{- end }} + {{- end }} +{{- end }} + + +{{- with .Site.Social.twitter }} + +{{- end }} \ No newline at end of file