From 74ce5dc84136467b563be6efa4246d29ad6127f7 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Sat, 23 Mar 2024 16:34:39 -0700 Subject: [PATCH] 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 <0urobor0s@users.noreply.github.com> --- hugolib/embedded_templates_test.go | 20 +++---- tpl/tplimpl/embedded/templates/schema.html | 67 +++++++++++++++++----- 2 files changed, 63 insertions(+), 24 deletions(-) diff --git a/hugolib/embedded_templates_test.go b/hugolib/embedded_templates_test.go index c409b0fbd..5ef92597c 100644 --- a/hugolib/embedded_templates_test.go +++ b/hugolib/embedded_templates_test.go @@ -68,9 +68,9 @@ title: My Site - - - + + + `) b.AssertFileContent("public/mypage/index.html", ` @@ -81,17 +81,17 @@ title: My Site - - - - - - + + + + + + `) b.AssertFileContent("public/mysite/index.html", ` - + `) } 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 @@ - - +{{- with or .Title site.Title }} + +{{- end }} -{{- if .IsPage -}} -{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}} -{{ with .PublishDate }}{{ end}} -{{ with .Lastmod }}{{ end}} - +{{- with or .Description .Summary site.Params.Description }} + +{{- end }} -{{- $images := partial "_funcs/get-page-images" . -}} -{{- range first 6 $images -}} - -{{- end -}} - - - +{{- $ISO8601 := "2006-01-02T15:04:05-07:00" }} +{{- with .PublishDate }} + +{{- end }} + +{{- with .Lastmod }} + +{{- end }} + +{{- with .WordCount }} + +{{- end }} + +{{- $images := partial "_funcs/get-page-images" . }} +{{- range first 6 $images }} + +{{- 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. + +*/}} +{{- $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 }} + {{- end -}}