diff options
author | Joe Mooring <[email protected]> | 2024-03-23 16:34:39 -0700 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-03-28 14:56:02 +0100 |
commit | 74ce5dc84136467b563be6efa4246d29ad6127f7 (patch) | |
tree | 8b2c15f22f3bd740877e1c34a4a0f0114659c1af /tpl | |
parent | 54a8f0ce21015df7f9927dca358b6d09a560e37b (diff) | |
download | hugo-74ce5dc84136467b563be6efa4246d29ad6127f7.tar.gz hugo-74ce5dc84136467b563be6efa4246d29ad6127f7.zip |
tpl/tplimpl: Update schema template
Changes:
- Remove trailing comma from list of keywords.
- Improve keywords precedence:
1. Use "keywords" term page titles.
2. Use "keywords" from front matter if "keywords" is not a taxonomy.
3. Use "tags" term page titles.
4. Use term page titles from all taxonomies.
- Enable schema for all page kinds, previously limited to kind = page.
- Remove trailing slashes from void elements.
- Improve readability.
Closes #7570
Co-authored by: 0urobor0s <[email protected]>
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/tplimpl/embedded/templates/schema.html | 69 |
1 files changed, 54 insertions, 15 deletions
diff --git a/tpl/tplimpl/embedded/templates/schema.html b/tpl/tplimpl/embedded/templates/schema.html index 8a55afe80..c4e89abd6 100644 --- a/tpl/tplimpl/embedded/templates/schema.html +++ b/tpl/tplimpl/embedded/templates/schema.html @@ -1,17 +1,56 @@ -<meta itemprop="name" content="{{ .Title }}"> -<meta itemprop="description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}"> - -{{- if .IsPage -}} -{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}} -{{ with .PublishDate }}<meta itemprop="datePublished" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end}} -{{ with .Lastmod }}<meta itemprop="dateModified" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end}} -<meta itemprop="wordCount" content="{{ .WordCount }}"> - -{{- $images := partial "_funcs/get-page-images" . -}} -{{- range first 6 $images -}} - <meta itemprop="image" content="{{ .Permalink }}" /> -{{- end -}} +{{- with or .Title site.Title }} + <meta itemprop="name" content="{{ . }}"> +{{- end }} + +{{- with or .Description .Summary site.Params.Description }} + <meta itemprop="description" content="{{ . }}"> +{{- end }} + +{{- $ISO8601 := "2006-01-02T15:04:05-07:00" }} +{{- with .PublishDate }} + <meta itemprop="datePublished" {{ .Format $ISO8601 | printf "content=%q" | safeHTMLAttr }}> +{{- end }} + +{{- with .Lastmod }} + <meta itemprop="dateModified" {{ .Format $ISO8601 | printf "content=%q" | safeHTMLAttr }}> +{{- end }} + +{{- with .WordCount }} + <meta itemprop="wordCount" content="{{ . }}"> +{{- end }} + +{{- $images := partial "_funcs/get-page-images" . }} +{{- range first 6 $images }} + <meta itemprop="image" content="{{ .Permalink }}"> +{{- end }} + +{{- /* +Keywords precedence: + +1. Use "keywords" term page titles. +2. Use "keywords" from front matter if "keywords" is not a taxonomy. +3. Use "tags" term page titles. +4. Use term page titles from all taxonomies. -<!-- Output all taxonomies as schema.org keywords --> -<meta itemprop="keywords" content="{{ if .IsPage}}{{ range $index, $tag := .Params.tags }}{{ $tag }},{{ end }}{{ else }}{{ range $plural, $terms := .Site.Taxonomies }}{{ range $term, $val := $terms }}{{ printf "%s," $term }}{{ end }}{{ end }}{{ end }}" /> +*/}} +{{- $keywords := slice }} +{{- range .GetTerms "keywords" }} + {{- $keywords = $keywords | append .Title }} +{{- else }} + {{- with .Keywords }} + {{- $keywords = . }} + {{- else }} + {{- range .GetTerms "tags" }} + {{- $keywords = $keywords | append .Title }} + {{- else }} + {{- range $taxonomy, $_ := site.Taxonomies }} + {{- range $.GetTerms $taxonomy }} + {{- $keywords = $keywords | append .Title }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} +{{- with $keywords }} + <meta itemprop="keywords" content="{{ delimit . `,` }}"> {{- end -}} |