From 7d676d80d4e7b1d02fc85b6e10eb9335b1b80eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sat, 4 Nov 2023 00:37:24 +0100 Subject: [PATCH] taxonomy: humanize term on missing term title #713 --- layouts/_default/index.json | 2 +- layouts/_default/index.search.js | 2 +- layouts/_default/taxonomy.html | 5 ++++- layouts/_default/term.html | 2 +- layouts/partials/breadcrumbs.html | 2 +- layouts/partials/header.html | 2 +- layouts/partials/opengraph.html | 4 ++-- layouts/partials/term-list.html | 4 ++-- layouts/partials/toc-id.html | 2 +- layouts/partials/twitter_cards.html | 2 +- 10 files changed, 15 insertions(+), 12 deletions(-) diff --git a/layouts/_default/index.json b/layouts/_default/index.json index c4d663a17b..217fffcc3c 100644 --- a/layouts/_default/index.json +++ b/layouts/_default/index.json @@ -8,7 +8,7 @@ {{- else if eq .Kind "term" }} {{- $taxonomy_page := .Site.GetPage .Data.Plural }} {{- $title = default (default .Data.Singular (i18n .Data.Singular)) $taxonomy_page.Params.SingularTitle }} - {{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) (default .Data.Term .Title) }} + {{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) (default (humanize .Data.Term) .Title) }} {{- end }} {{- $pages = $pages | append (dict "uri" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) diff --git a/layouts/_default/index.search.js b/layouts/_default/index.search.js index a8dac2e8b3..014f30652b 100644 --- a/layouts/_default/index.search.js +++ b/layouts/_default/index.search.js @@ -8,7 +8,7 @@ {{- else if eq .Kind "term" }} {{- $taxonomy_page := .Site.GetPage .Data.Plural }} {{- $title = default (default .Data.Singular (i18n .Data.Singular)) $taxonomy_page.Params.SingularTitle }} - {{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) (default .Data.Term .Title) }} + {{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) (default (humanize .Data.Term) .Title) }} {{- end }} {{- $pages = $pages | append (dict "uri" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) diff --git a/layouts/_default/taxonomy.html b/layouts/_default/taxonomy.html index d1298d0360..8bc304d63b 100644 --- a/layouts/_default/taxonomy.html +++ b/layouts/_default/taxonomy.html @@ -19,7 +19,10 @@ {{- end }} {{- end }} {{- if $len }} - {{- $pages = $pages| append (dict "Title" (default .Page.Data.Term .Page.Title) "Page" . "Len" $len )}} + {{- $pages = $pages| append (dict "Title" (default (humanize .Page.Data.Term) .Page.Title) "Page" . "Len" $len )}} + {{- end }} + {{- if not .Page.Title }} + {{- warnf "%q: You have not given a 'title' in the frontmatter of your term page, the humanized term will be used instead" .Page.File.Filename }} {{- end }} {{- end }} {{- range sort $pages ".Title" }} diff --git a/layouts/_default/term.html b/layouts/_default/term.html index 60a4d327c6..2f95bcc177 100644 --- a/layouts/_default/term.html +++ b/layouts/_default/term.html @@ -7,7 +7,7 @@ {{- $taxonomy_page := .Site.GetPage .Data.Plural }} {{- $title := default (default .Data.Singular (i18n .Data.Singular)) $taxonomy_page.Params.SingularTitle }} -{{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) (default .Data.Term .Title) }} +{{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) (default (humanize .Data.Term) .Title) }}

{{ $title }}

{{- .Content }} {{- $lastCapital := "" }} diff --git a/layouts/partials/breadcrumbs.html b/layouts/partials/breadcrumbs.html index 4906d6814b..f8865f3dfa 100644 --- a/layouts/partials/breadcrumbs.html +++ b/layouts/partials/breadcrumbs.html @@ -37,7 +37,7 @@ {{- else if eq $to.Kind "term" }} {{- $taxonomy_page := $to.Site.GetPage $to.Data.Plural }} {{- $title = default (default $to.Data.Singular (i18n $to.Data.Singular)) $taxonomy_page.Params.SingularTitle }} - {{- $title = printf "%s %s %s" $title (default "::" $to.Site.Params.titleSeparator) (default $to.Data.Term $to.Title) }} + {{- $title = printf "%s %s %s" $title (default "::" $to.Site.Params.titleSeparator) (default (humanize $to.Data.Term) $to.Title) }} {{- end }} {{- if not $title }} {{- $title = $to.Site.Title }} diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 1124851157..75dcb57706 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -18,7 +18,7 @@ {{- else if eq .Kind "term" }} {{- $taxonomy_page := .Site.GetPage .Data.Plural }} {{- $title = default (default .Data.Singular (i18n .Data.Singular)) $taxonomy_page.Params.SingularTitle }} - {{- $title = printf "%s %s %s" (default .Data.Term .Title) (default "::" .Site.Params.titleSeparator) $title }} + {{- $title = printf "%s %s %s" (default (humanize .Data.Term) .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 }} diff --git a/layouts/partials/opengraph.html b/layouts/partials/opengraph.html index 5906747fd7..13a51f35d9 100644 --- a/layouts/partials/opengraph.html +++ b/layouts/partials/opengraph.html @@ -14,7 +14,7 @@ {{- else if eq .Kind "term" }} {{- $taxonomy_page := .Site.GetPage .Data.Plural }} {{- $title = default (default .Data.Singular (i18n .Data.Singular)) $taxonomy_page.Params.SingularTitle }} - {{- $title = printf "%s %s %s" (default .Data.Term .Title) (default "::" .Site.Params.titleSeparator) $title }} + {{- $title = printf "%s %s %s" (default (humanize .Data.Term) .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 }} @@ -54,7 +54,7 @@ {{- else if eq .Kind "term" }} {{- $taxonomy_page := .Site.GetPage .Data.Plural }} {{- $title = default (default .Data.Singular (i18n .Data.Singular)) $taxonomy_page.Params.SingularTitle }} - {{- $title = printf "%s %s %s" (default .Data.Term .Title) (default "::" .Site.Params.titleSeparator) $title }} + {{- $title = printf "%s %s %s" (default (humanize .Data.Term) .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 }} diff --git a/layouts/partials/term-list.html b/layouts/partials/term-list.html index 4214f16518..a0680cf365 100644 --- a/layouts/partials/term-list.html +++ b/layouts/partials/term-list.html @@ -21,11 +21,11 @@ {{- end }} {{- $term_key := ($term | plainify | anchorize) }} {{- with $page.Site.GetPage (printf "%s/%s" $taxonomy $term_key) }} - {{- $term_pages = $term_pages | append (dict "Title" (default .Data.Term .Title) "Term" . )}} + {{- $term_pages = $term_pages | append (dict "Title" (default (humanize .Data.Term) .Title) "Term" . )}} {{- else }} {{- $term_key = ($term | urlize) }} {{- with $page.Site.GetPage (printf "%s/%s" $taxonomy $term_key) }} - {{- $term_pages = $term_pages | append (dict "Title" (default .Data.Term .Title) "Term" . )}} + {{- $term_pages = $term_pages | append (dict "Title" (default (humanize .Data.Term) .Title) "Term" . )}} {{- end }} {{- end }} {{- end }} diff --git a/layouts/partials/toc-id.html b/layouts/partials/toc-id.html index c974c64c7f..94ca1ef6e9 100644 --- a/layouts/partials/toc-id.html +++ b/layouts/partials/toc-id.html @@ -11,7 +11,7 @@ {{- end }} {{- end }} {{- if $len }} - {{- $pages = $pages| append (dict "Title" (default .Page.Data.Term .Page.Title) "Page" . "Len" $len )}} + {{- $pages = $pages| append (dict "Title" (default (humanize .Page.Data.Term) .Page.Title) "Page" . "Len" $len )}} {{- end }} {{- end }} {{- else if eq .Kind "term" }} diff --git a/layouts/partials/twitter_cards.html b/layouts/partials/twitter_cards.html index e71c05b53a..47ed0d4f95 100644 --- a/layouts/partials/twitter_cards.html +++ b/layouts/partials/twitter_cards.html @@ -10,7 +10,7 @@ {{- else if eq .Kind "term" }} {{- $taxonomy_page := .Site.GetPage .Data.Plural }} {{- $title = default (default .Data.Singular (i18n .Data.Singular)) $taxonomy_page.Params.SingularTitle }} - {{- $title = printf "%s %s %s" (default .Data.Term .Title) (default "::" .Site.Params.titleSeparator) $title }} + {{- $title = printf "%s %s %s" (default (humanize .Data.Term) .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 }}