Skip to content

Commit

Permalink
fix: delete duplicate site title
Browse files Browse the repository at this point in the history
  • Loading branch information
reuixiy committed Sep 3, 2019
1 parent 94f4832 commit 77a80fd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
3 changes: 1 addition & 2 deletions layouts/index.sectionsatom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
{{- partial "components/author.html" $page -}}
{{- $author := ($page.Scratch.Get "author") -}}
<entry>
{{ $pageTitle := printf "%s | %s" .Title .Site.Title | safeHTML -}}
<title type="text">{{ $pageTitle }}</title>
<title type="text">{{ .Title | safeHTML }}</title>
<link rel="alternate" type="text/html" href="{{ .Permalink }}" />
<id>{{ .Permalink }}</id>
<updated>{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}</updated>
Expand Down
3 changes: 1 addition & 2 deletions layouts/index.sectionsrss.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
{{- partial "components/author.html" $page -}}
{{- $author := ($page.Scratch.Get "author") -}}
<item>
{{ $pageTitle := printf "%s | %s" .Title .Site.Title | safeHTML -}}
<title>{{ $pageTitle }}</title>
<title>{{ .Title | safeHTML }}</title>
<link>{{ .Permalink }}</link>
<guid isPermaLink="true">{{ .Permalink }}</guid>
<pubDate>{{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
Expand Down
10 changes: 6 additions & 4 deletions layouts/partials/components/json-ld.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
<!-- https://json-ld.org/ -->
<!-- https://search.google.com/structured-data/testing-tool -->
{{- $Deliver := .Deliver -}}
{{- $title := .title -}}
{{- $description := .description -}}
{{- $keywords := .keywords -}}
{{- $baseURLWithLangFix := print `/` | absLangURL -}}
<!-- Title -->
{{- partial "components/title.html" $Deliver -}}
{{- $rawTitle := $Deliver.Scratch.Get "rawTitle" -}}
<!-- Auto Detect Images -->
{{- if $Deliver.Site.Params.autoDetectImages -}}
{{- partial "components/auto-detect-images.html" $Deliver -}}
Expand Down Expand Up @@ -64,7 +66,7 @@
{{ with $author.copyright -}}
"license": {{ . | plainify }},
{{ end -}}
"name": {{ $title }}
"name": {{ $rawTitle }}
}
</script>
{{- else if and $Deliver.IsPage (in $Deliver.Site.Params.postSections $Deliver.Section) -}}
Expand All @@ -75,7 +77,7 @@
"datePublished": {{ $pubDate }},
"dateModified": {{ $modDate }},
"url": {{ $Deliver.Permalink }},
"headline": {{ $title }},
"headline": {{ $rawTitle }},
"description": {{ $description }},
"keywords": {{ $keywords }},
"inLanguage" : "{{ $Deliver.Site.LanguageCode }}",
Expand Down Expand Up @@ -136,7 +138,7 @@
"datePublished": {{ $pubDate }},
"dateModified": {{ $modDate }},
"url": {{ $Deliver.Permalink }},
"name": {{ $title }},
"name": {{ $rawTitle }},
"description": {{ $description }},
"keywords": {{ $keywords }},
{{ with $Deliver.Site.Params.siteLogo -}}
Expand Down
6 changes: 4 additions & 2 deletions layouts/partials/components/open-graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
<!-- https://stackoverflow.com/a/29831974 -->
<!-- https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/opengraph.html -->
{{- $Deliver := .Deliver -}}
{{- $title := .title -}}
{{- $description := .description -}}
{{- $keywords := .keywords -}}
<!-- Title -->
{{- partial "components/title.html" $Deliver -}}
{{- $rawTitle := $Deliver.Scratch.Get "rawTitle" -}}
<!-- Auto Detect Images -->
{{- if $Deliver.Site.Params.autoDetectImages -}}
{{- partial "components/auto-detect-images.html" $Deliver -}}
Expand Down Expand Up @@ -41,7 +43,7 @@
{{- end -}}
{{- $languageCode := $Deliver.Scratch.Get "languageCode" -}}

<meta property="og:title" content="{{ $title }}" />
<meta property="og:title" content="{{ $rawTitle }}" />
<meta property="og:description" content="{{ $description }}" />
<meta property="og:url" content="{{ $Deliver.Permalink }}" />
<meta property="og:site_name" content="{{ $Deliver.Site.Title }}" />
Expand Down
9 changes: 9 additions & 0 deletions layouts/partials/components/title.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@
{{- if eq .Kind "home" -}}
{{- $title := .Site.Title -}}
{{- .Scratch.Set "title" $title -}}
{{- .Scratch.Set "rawTitle" $title -}}
<!-- Taxonomy -->
{{- 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 -}}
<!-- Taxonomy Term -->
{{- 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 -}}
<!-- Section -->
{{- 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 -}}
<!-- Page -->
{{- else -}}
{{- $title := printf "%s | %s" (.Title | plainify) .Site.Title -}}
{{- $rawTitle := .Title | plainify -}}
{{- .Scratch.Set "title" $title -}}
{{- .Scratch.Set "rawTitle" $rawTitle -}}
{{- end -}}
4 changes: 2 additions & 2 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
{{- $Deliver := . -}}
<!-- JSON-LD -->
{{- 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 }}

<!-- Twitter Cards -->
Expand All @@ -107,7 +107,7 @@
{{- end }}
<!-- Open Graph -->
{{- 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 }}
Expand Down

0 comments on commit 77a80fd

Please sign in to comment.