refactor(head): rewrite title function

This commit is contained in:
Jimmy Cai 2020-09-11 22:50:30 +02:00
parent b064b5ef85
commit 6f5ee1bbdb
No known key found for this signature in database
GPG Key ID: 3EA408E527F37B18
2 changed files with 32 additions and 9 deletions

View File

@ -1,16 +1,38 @@
{{- $title := .Title -}}
{{- $siteTitle := .Site.Title -}}
{{- $authorName := .Site.Author.name -}}
{{- if .IsHome -}}
<!-- Homepage, and it's pagination -->
<!-- Build paginator -->
{{ $pages := where .Site.RegularPages "Section" "in" .Site.Params.mainSections }}
{{ $notHidden := where .Site.RegularPages "Params.hidden" "!=" true }}
{{ $filtered := ($pages | intersect $notHidden) }}
{{ $pag := .Paginate ($filtered) }}
{{ if .Paginator.HasPrev }}{{ .Paginator }} - {{ end }}{{ $siteTitle }}
{{ if .Paginator.HasPrev }}
<!-- Paginated. Append page number to title -->
{{ $title = printf "%s - %s" .Paginator $siteTitle }}
{{ else }}
{{ $title = $siteTitle}}
{{ end }}
{{- else if eq .Kind "term" -}}
{{- $pag := .Paginate (where .Data.Pages "Type" "post") -}}
{{ title .Data.Singular }}: {{ $title }}{{ if .Paginator.HasPrev }} - {{ .Paginator }}{{ end }} - {{ $siteTitle }}
{{- else -}}
{{- $title -}}
<!-- Taxonomy page -->
<!-- Build paginator -->
{{ $notHidden := where .Pages "Params.hidden" "!=" true }}
{{ $pag := .Paginate ($notHidden) }}
<!-- {TAXONOMY_TYPE}: {TAXONOMY_TERM} -->
{{ $title = slice (title .Data.Singular) ": " $title }}
{{ if .Paginator.HasPrev }}
<!-- Add page number-->
{{ $title = $title | append " - " .Paginator }}
{{ end }}
{{ $title = $title | append " - " $siteTitle }}
{{ $title = delimit $title "" }}
{{- end -}}
{{ return $title }}

View File

@ -3,7 +3,8 @@
<meta name='viewport' content='width=device-width, initial-scale=1'>
<meta name='description' content='{{ chomp (partial "data/description" . | plainify ) }}'>
<title>{{ (trim (partial "data/title" .) "\n" ) | safeHTML }}</title>
{{- $title := partial "data/title" . -}}
<title>{{ $title }}</title>
<link rel='canonical' href='{{ .Permalink }}'>
{{- partial "head/style.html" . -}}