theme: merge title generation into one partial #825

This commit is contained in:
Sören Weber 2024-04-07 22:13:52 +02:00
parent b8eb8c3bbb
commit 07f5acc184
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
7 changed files with 19 additions and 20 deletions

View file

@ -4,7 +4,7 @@
<html lang="{{ .Page.Language.LanguageCode | default "en" }}" dir="{{ .Page.Language.LanguageDirection | default (T "Reading-direction") | default "ltr" }}"> <html lang="{{ .Page.Language.LanguageCode | default "en" }}" dir="{{ .Page.Language.LanguageDirection | default (T "Reading-direction") | default "ltr" }}">
<head> <head>
{{- partial "meta.html" . }} {{- partial "meta.html" . }}
{{- $title := partial "pageHelper/fullTitle.hugo" (dict "page" . "invert" true) }} {{- $title := partial "pageHelper/title.hugo" (dict "page" . "fullyQualified" true "reverse" true) }}
<title>{{ $title }}</title> <title>{{ $title }}</title>
<base href="{{ .Site.BaseURL }}"> <base href="{{ .Site.BaseURL }}">
{{- partialCached "favicon.html" . }} {{- partialCached "favicon.html" . }}

View file

@ -31,7 +31,7 @@
{{- range $i, $e := $breadcrumbReversed }} {{- range $i, $e := $breadcrumbReversed }}
{{- $to := $e }} {{- $to := $e }}
{{- $depth = add $depth 1 }} {{- $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) }} {{- $url := partial "relLangPrettyUglyURL.hugo" (dict "to" $to) }}
{{- $isPage := eq $url $pageurl }} {{- $isPage := eq $url $pageurl }}
{{- $isLast := eq $url $lasturl }} {{- $isLast := eq $url $lasturl }}

View file

@ -16,7 +16,7 @@
{{- partial "meta.html" . }} {{- partial "meta.html" . }}
{{- $page := . }} {{- $page := . }}
{{- $link := "<link href=\"%s\" rel=\"%s\" type=\"%s\" title=\"%s\">" }} {{- $link := "<link href=\"%s\" rel=\"%s\" type=\"%s\" title=\"%s\">" }}
{{- $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>{{ $title }}</title> <title>{{ $title }}</title>
{{- if .IsTranslated -}} {{- if .IsTranslated -}}

View file

@ -10,7 +10,7 @@
{{- with or site.Title site.Params.title | plainify }} {{- with or site.Title site.Params.title | plainify }}
<meta property="og:site_name" content="{{ . }}"> <meta property="og:site_name" content="{{ . }}">
{{- end }} {{- end }}
<meta property="og:title" content="{{ partial "pageHelper/fullTitle.hugo" (dict "page" . "invert" true "format" $format "outputFormat" $outputFormat) | plainify }}"> <meta property="og:title" content="{{ partial "pageHelper/title.hugo" (dict "page" . "fullyQualified" true "reverse" true "format" $format "outputFormat" $outputFormat) | plainify }}">
{{- with or .Description .Summary site.Params.description | plainify }} {{- with or .Description .Summary site.Params.description | plainify }}
<meta property="og:description" content="{{ . }}"> <meta property="og:description" content="{{ . }}">
@ -23,7 +23,7 @@
{{- if .IsPage }} {{- if .IsPage }}
<meta property="og:type" content="article"> <meta property="og:type" content="article">
{{- with .FirstSection }} {{- with .FirstSection }}
<meta property="article:section" content="{{ partial "pageHelper/fullTitle.hugo" (dict "page" . "invert" true "format" $format "outputFormat" $outputFormat) | plainify }}"> <meta property="article:section" content="{{ partial "pageHelper/title.hugo" (dict "page" . "fullyQualified" true "reverse" true "format" $format "outputFormat" $outputFormat) | plainify }}">
{{- end }} {{- end }}
{{- $iso8601 := "2006-01-02T15:04:05-07:00" }} {{- $iso8601 := "2006-01-02T15:04:05-07:00" }}
{{- with .PublishDate }} {{- with .PublishDate }}

View file

@ -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 }}

View file

@ -6,7 +6,7 @@
{{- $format := $.format | default (partial "get-format.hugo" .) }} {{- $format := $.format | default (partial "get-format.hugo" .) }}
{{- $outputFormat := $.outputFormat | default (partial "output-format.hugo" (dict "page" . "format" $format)) }} {{- $outputFormat := $.outputFormat | default (partial "output-format.hugo" (dict "page" . "format" $format)) }}
{{- $title = .Title }} {{- $title = .Title }}
{{- if $.useLinkTitle }} {{- if $.linkTitle }}
{{- $title = or $.page.Params.menuTitle $.page.LinkTitle $title }} {{- $title = or $.page.Params.menuTitle $.page.LinkTitle $title }}
{{- end }} {{- end }}
@ -20,13 +20,23 @@
{{- $taxonomy_page := .Site.GetPage .Data.Plural }} {{- $taxonomy_page := .Site.GetPage .Data.Plural }}
{{- $taxonomy_title := default (default $taxonomy_page.Data.Singular (i18n $taxonomy_page.Data.Singular)) $taxonomy_page.Params.SingularTitle }} {{- $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 }} {{- $term_title := default (humanize .Data.Term | strings.Title) .Title }}
{{- if $.useLinkTitle }} {{- if $.linkTitle }}
{{- $title = printf "%s" $term_title }} {{- $title = printf "%s" $term_title }}
{{- else if $.invert }} {{- else if $.reverse }}
{{- $title = printf "%s %s %s" $term_title (default "::" .Site.Params.titleSeparator) $taxonomy_title }} {{- $title = printf "%s %s %s" $term_title (default "::" .Site.Params.titleSeparator) $taxonomy_title }}
{{- else }} {{- else }}
{{- $title = printf "%s %s %s" $taxonomy_title (default "::" .Site.Params.titleSeparator) $term_title }} {{- $title = printf "%s %s %s" $taxonomy_title (default "::" .Site.Params.titleSeparator) $term_title }}
{{- end }} {{- end }}
{{- 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 }} {{- end }}
{{- return $title }} {{- return $title }}

View file

@ -6,7 +6,7 @@
{{- else }} {{- else }}
<meta name="twitter:card" content="summary"> <meta name="twitter:card" content="summary">
{{- end }} {{- end }}
<meta name="twitter:title" content="{{ partial "pageHelper/fullTitle.hugo" (dict "page" . "invert" true) }}"> <meta name="twitter:title" content="{{ partial "pageHelper/title.hugo" (dict "page" . "fullyQualified" true "reverse" true) }}">
<meta name="twitter:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}"> <meta name="twitter:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}">
{{- $twitterSite := "" }} {{- $twitterSite := "" }}