From 07f5acc184c037bc9bbef7ef5bd7ebcd5f239c50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sun, 7 Apr 2024 22:13:52 +0200 Subject: [PATCH] theme: merge title generation into one partial #825 --- layouts/404.html | 2 +- layouts/partials/breadcrumbs.html | 2 +- layouts/partials/header.html | 2 +- layouts/partials/opengraph.html | 4 ++-- layouts/partials/pageHelper/fullTitle.hugo | 11 ----------- layouts/partials/pageHelper/title.hugo | 16 +++++++++++++--- layouts/partials/twitter_cards.html | 2 +- 7 files changed, 19 insertions(+), 20 deletions(-) delete mode 100644 layouts/partials/pageHelper/fullTitle.hugo diff --git a/layouts/404.html b/layouts/404.html index b49b75b3f3..325045c7b1 100644 --- a/layouts/404.html +++ b/layouts/404.html @@ -4,7 +4,7 @@ {{- partial "meta.html" . }} - {{- $title := partial "pageHelper/fullTitle.hugo" (dict "page" . "invert" true) }} + {{- $title := partial "pageHelper/title.hugo" (dict "page" . "fullyQualified" true "reverse" true) }} {{ $title }} {{- partialCached "favicon.html" . }} diff --git a/layouts/partials/breadcrumbs.html b/layouts/partials/breadcrumbs.html index b88e818229..227feb0f85 100644 --- a/layouts/partials/breadcrumbs.html +++ b/layouts/partials/breadcrumbs.html @@ -31,7 +31,7 @@ {{- range $i, $e := $breadcrumbReversed }} {{- $to := $e }} {{- $depth = add $depth 1 }} - {{- $title := partial "pageHelper/title.hugo" (dict "page" $to "useLinkTitle" true) }} + {{- $title := partial "pageHelper/title.hugo" (dict "page" $to "linkTitle" true) }} {{- $url := partial "relLangPrettyUglyURL.hugo" (dict "to" $to) }} {{- $isPage := eq $url $pageurl }} {{- $isLast := eq $url $lasturl }} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 54bda22e64..feb0f0592e 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -16,7 +16,7 @@ {{- partial "meta.html" . }} {{- $page := . }} {{- $link := "" }} - {{- $title := partial "pageHelper/fullTitle.hugo" (dict "page" . "invert" true "format" $format "outputFormat" $outputFormat) }} + {{- $title := partial "pageHelper/title.hugo" (dict "page" . "fullyQualified" true "reverse" true "format" $format "outputFormat" $outputFormat) }} {{ $title }} {{- if .IsTranslated -}} diff --git a/layouts/partials/opengraph.html b/layouts/partials/opengraph.html index b69a70d8a4..9dba98d359 100644 --- a/layouts/partials/opengraph.html +++ b/layouts/partials/opengraph.html @@ -10,7 +10,7 @@ {{- with or site.Title site.Params.title | plainify }} {{- end }} - + {{- with or .Description .Summary site.Params.description | plainify }} @@ -23,7 +23,7 @@ {{- if .IsPage }} {{- with .FirstSection }} - + {{- end }} {{- $iso8601 := "2006-01-02T15:04:05-07:00" }} {{- with .PublishDate }} diff --git a/layouts/partials/pageHelper/fullTitle.hugo b/layouts/partials/pageHelper/fullTitle.hugo deleted file mode 100644 index 38f573f1bd..0000000000 --- a/layouts/partials/pageHelper/fullTitle.hugo +++ /dev/null @@ -1,11 +0,0 @@ -{{- $title := partial "pageHelper/title.hugo" . }} -{{- with .page }} - {{- if and $title site.Title (not (eq $title site.Title)) }} - {{- if $.invert }} - {{- $title = printf "%s %s %s" $title (default "::" site.Params.titleSeparator) site.Title }} - {{- else }} - {{- $title = printf "%s %s %s" site.Title (default "::" site.Params.titleSeparator) $title }} - {{- end }} - {{- end }} -{{- end }} -{{- return $title }} \ No newline at end of file diff --git a/layouts/partials/pageHelper/title.hugo b/layouts/partials/pageHelper/title.hugo index d3d1ab767f..51e664492c 100644 --- a/layouts/partials/pageHelper/title.hugo +++ b/layouts/partials/pageHelper/title.hugo @@ -6,7 +6,7 @@ {{- $format := $.format | default (partial "get-format.hugo" .) }} {{- $outputFormat := $.outputFormat | default (partial "output-format.hugo" (dict "page" . "format" $format)) }} {{- $title = .Title }} - {{- if $.useLinkTitle }} + {{- if $.linkTitle }} {{- $title = or $.page.Params.menuTitle $.page.LinkTitle $title }} {{- end }} @@ -20,13 +20,23 @@ {{- $taxonomy_page := .Site.GetPage .Data.Plural }} {{- $taxonomy_title := default (default $taxonomy_page.Data.Singular (i18n $taxonomy_page.Data.Singular)) $taxonomy_page.Params.SingularTitle }} {{- $term_title := default (humanize .Data.Term | strings.Title) .Title }} - {{- if $.useLinkTitle }} + {{- if $.linkTitle }} {{- $title = printf "%s" $term_title }} - {{- else if $.invert }} + {{- else if $.reverse }} {{- $title = printf "%s %s %s" $term_title (default "::" .Site.Params.titleSeparator) $taxonomy_title }} {{- else }} {{- $title = printf "%s %s %s" $taxonomy_title (default "::" .Site.Params.titleSeparator) $term_title }} {{- end }} {{- end }} + + {{- if $.fullyQualified }} + {{- if and $title site.Title (not (eq $title site.Title)) }} + {{- if $.reverse }} + {{- $title = printf "%s %s %s" $title (default "::" site.Params.titleSeparator) site.Title }} + {{- else }} + {{- $title = printf "%s %s %s" site.Title (default "::" site.Params.titleSeparator) $title }} + {{- end }} + {{- end }} + {{- end }} {{- end }} {{- return $title }} \ No newline at end of file diff --git a/layouts/partials/twitter_cards.html b/layouts/partials/twitter_cards.html index fb286db0f0..2e464fffe2 100644 --- a/layouts/partials/twitter_cards.html +++ b/layouts/partials/twitter_cards.html @@ -6,7 +6,7 @@ {{- else }} {{- end }} - + {{- $twitterSite := "" }}