From 77a80fd473f03a31c71266f23126f384e20a38ef Mon Sep 17 00:00:00 2001 From: reuixiy Date: Wed, 4 Sep 2019 01:34:17 +0800 Subject: [PATCH] fix: delete duplicate site title --- layouts/index.sectionsatom.xml | 3 +-- layouts/index.sectionsrss.xml | 3 +-- layouts/partials/components/json-ld.html | 10 ++++++---- layouts/partials/components/open-graph.html | 6 ++++-- layouts/partials/components/title.html | 9 +++++++++ layouts/partials/head.html | 4 ++-- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/layouts/index.sectionsatom.xml b/layouts/index.sectionsatom.xml index 2b51ce5d..cb917baa 100644 --- a/layouts/index.sectionsatom.xml +++ b/layouts/index.sectionsatom.xml @@ -34,8 +34,7 @@ {{- partial "components/author.html" $page -}} {{- $author := ($page.Scratch.Get "author") -}} - {{ $pageTitle := printf "%s | %s" .Title .Site.Title | safeHTML -}} - {{ $pageTitle }} + {{ .Title | safeHTML }} {{ .Permalink }} {{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }} diff --git a/layouts/index.sectionsrss.xml b/layouts/index.sectionsrss.xml index 31f0bb80..a3a920c3 100644 --- a/layouts/index.sectionsrss.xml +++ b/layouts/index.sectionsrss.xml @@ -37,8 +37,7 @@ {{- partial "components/author.html" $page -}} {{- $author := ($page.Scratch.Get "author") -}} - {{ $pageTitle := printf "%s | %s" .Title .Site.Title | safeHTML -}} - {{ $pageTitle }} + {{ .Title | safeHTML }} {{ .Permalink }} {{ .Permalink }} {{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }} diff --git a/layouts/partials/components/json-ld.html b/layouts/partials/components/json-ld.html index c5c8c82d..6e6e4f08 100644 --- a/layouts/partials/components/json-ld.html +++ b/layouts/partials/components/json-ld.html @@ -2,10 +2,12 @@ {{- $Deliver := .Deliver -}} -{{- $title := .title -}} {{- $description := .description -}} {{- $keywords := .keywords -}} {{- $baseURLWithLangFix := print `/` | absLangURL -}} + +{{- partial "components/title.html" $Deliver -}} +{{- $rawTitle := $Deliver.Scratch.Get "rawTitle" -}} {{- if $Deliver.Site.Params.autoDetectImages -}} {{- partial "components/auto-detect-images.html" $Deliver -}} @@ -64,7 +66,7 @@ {{ with $author.copyright -}} "license": {{ . | plainify }}, {{ end -}} - "name": {{ $title }} + "name": {{ $rawTitle }} } {{- else if and $Deliver.IsPage (in $Deliver.Site.Params.postSections $Deliver.Section) -}} @@ -75,7 +77,7 @@ "datePublished": {{ $pubDate }}, "dateModified": {{ $modDate }}, "url": {{ $Deliver.Permalink }}, - "headline": {{ $title }}, + "headline": {{ $rawTitle }}, "description": {{ $description }}, "keywords": {{ $keywords }}, "inLanguage" : "{{ $Deliver.Site.LanguageCode }}", @@ -136,7 +138,7 @@ "datePublished": {{ $pubDate }}, "dateModified": {{ $modDate }}, "url": {{ $Deliver.Permalink }}, - "name": {{ $title }}, + "name": {{ $rawTitle }}, "description": {{ $description }}, "keywords": {{ $keywords }}, {{ with $Deliver.Site.Params.siteLogo -}} diff --git a/layouts/partials/components/open-graph.html b/layouts/partials/components/open-graph.html index db9b9e84..7a0c8580 100644 --- a/layouts/partials/components/open-graph.html +++ b/layouts/partials/components/open-graph.html @@ -4,9 +4,11 @@ {{- $Deliver := .Deliver -}} -{{- $title := .title -}} {{- $description := .description -}} {{- $keywords := .keywords -}} + +{{- partial "components/title.html" $Deliver -}} +{{- $rawTitle := $Deliver.Scratch.Get "rawTitle" -}} {{- if $Deliver.Site.Params.autoDetectImages -}} {{- partial "components/auto-detect-images.html" $Deliver -}} @@ -41,7 +43,7 @@ {{- end -}} {{- $languageCode := $Deliver.Scratch.Get "languageCode" -}} - + diff --git a/layouts/partials/components/title.html b/layouts/partials/components/title.html index cd746817..8bea40ff 100644 --- a/layouts/partials/components/title.html +++ b/layouts/partials/components/title.html @@ -2,23 +2,32 @@ {{- if eq .Kind "home" -}} {{- $title := .Site.Title -}} {{- .Scratch.Set "title" $title -}} + {{- .Scratch.Set "rawTitle" $title -}} {{- else if eq .Kind "taxonomyTerm" -}} {{- $title := printf "%s | %s" (.Title | default (.Type | title)) .Site.Title -}} + {{- $rawTitle := (.Title | default (.Type | title)) -}} {{- .Scratch.Set "title" $title -}} + {{- .Scratch.Set "rawTitle" $rawTitle -}} {{- else if eq .Kind "taxonomy" -}} {{- $taxonomyTermTitle := .Title | default .Data.Term | default (delimit (last 1 (split (strings.TrimSuffix "/_index.md" .Path) "/")) " ") -}} {{- with .Site.GetPage (printf "/%s" .Data.Plural) -}} {{- $title := printf "%s: %s | %s" (.Title | default (.Type | title)) $taxonomyTermTitle .Site.Title -}} + {{- $rawTitle := printf "%s: %s" (.Title | default (.Type | title)) $taxonomyTermTitle -}} {{- $.Scratch.Set "title" $title -}} + {{- $.Scratch.Set "rawTitle" $rawTitle -}} {{- end -}} {{- else if eq .Kind "section" -}} {{- $title := printf "%s | %s" (.Title | default (delimit (last 1 (split (strings.TrimSuffix "/_index.md" .Path) "/")) " ") | plainify) .Site.Title -}} + {{- $rawTitle := .Title | default (delimit (last 1 (split (strings.TrimSuffix "/_index.md" .Path) "/")) " ") | plainify -}} {{- .Scratch.Set "title" $title -}} + {{- .Scratch.Set "rawTitle" $rawTitle -}} {{- else -}} {{- $title := printf "%s | %s" (.Title | plainify) .Site.Title -}} + {{- $rawTitle := .Title | plainify -}} {{- .Scratch.Set "title" $title -}} + {{- .Scratch.Set "rawTitle" $rawTitle -}} {{- end -}} \ No newline at end of file diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 9d6d6c58..1f1a66c4 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -98,7 +98,7 @@ {{- $Deliver := . -}} {{- with .Site.Params.jsonLD -}} - {{ partial "components/json-ld.html" (dict "Deliver" $Deliver "title" $title "description" $description "keywords" $keywords) }} + {{ partial "components/json-ld.html" (dict "Deliver" $Deliver "description" $description "keywords" $keywords) }} {{- end }} @@ -107,7 +107,7 @@ {{- end }} {{- with .Site.Params.openGraph -}} - {{ partial "components/open-graph.html" (dict "Deliver" $Deliver "title" $title "description" $description "keywords" $keywords) }} + {{ partial "components/open-graph.html" (dict "Deliver" $Deliver "description" $description "keywords" $keywords) }} {{- end }} {{- with .Site.Params.googleSiteVerification }}