Add expanded title and description generation for taxonomy pages for SEO

This commit is contained in:
Paul Bakker 2018-06-29 11:48:06 +02:00
commit 812e80392e

View file

@ -1,20 +1,29 @@
{{- if eq .Kind "taxonomyTerm" }}
{{- range $key, $value := .Data.Terms.ByCount }}
{{- $.Scratch.Add "most_used" (slice $value.Name) }}
{{- end }}
{{- $description := printf "A full overview of all pages with %s, ordered by %s, such as: %s" .Data.Plural .Data.Singular ( delimit ( $.Scratch.Get "most_used" ) ", " ", and " ) | truncate 180 }}
{{- $.Scratch.Set "Description" $description }}
{{- $title := printf "Overview of all pages with %s, ordered by %s" .Data.Plural .Data.Singular }}
{{- $.Scratch.Set "Title" $title }}
{{- else if eq .Kind "taxonomy" }}
{{- $description := printf "Overview of all pages with the %s #%s, such as: %s" .Data.Singular $.Title ( index .Pages 0).Title | truncate 160 }}
{{- $.Scratch.Set "Description" $description }}
{{- $title := printf "Overview of all pages with the %s #%s" .Data.Singular $.Title }}
{{- $.Scratch.Set "Title" $title }}
{{- end }}
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<!-- Site Title, Description, Author, and Favicon -->
{{- with .Title | default .Site.Title }}
{{- with ($.Scratch.Get "Title") | default .Title | default .Site.Title }}
<title>{{ . }}</title>
<meta property="og:title" content="{{ . }}" />
<meta name="twitter:title" content="{{ . | truncate 70 }}" />
{{- end }}
{{- if eq .Kind "taxonomyTerm" }}
{{- $text := printf "Overview of all pages by %s" .Data.Singular }}
{{- $.Scratch.Set "Description" $text }}
{{- else if eq .Kind "taxonomy" }}
{{- $text := printf "Overview of all pages with the %s #%s" .Data.Singular $.Title }}
{{- $.Scratch.Set "Description" $text }}
{{- end }}
{{- with .Description | default .Params.subtitle | default .Summary | default ($.Scratch.Get "Description") }}
<meta name="description" content="{{ . }}">
<meta property="og:description" content="{{ . }}">