Repository: gohugoio/hugo (language: go)

Issue:
Remove last comma from schema.html template
With the introduction of delimit in #683 it is possible to use it
instead of range while also removing the last comma in keywords tag.


Discussion / hints:
[![CLA assistant check](https://cla-assistant.io/pull/badge/signed)](https://cla-assistant.io/gohugoio/hugo?pullRequest=7570) <br/>All committers have signed the CLA.
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a **bug** and you can still reproduce this error on the <code>master</code> branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a **feature request**, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

This still happens in master but is not critical.
The relevant url is [https://schema.org/keywords](https://schema.org/keywords)
This PR has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
Please check https://github.com/gohugoio/hugo/blob/master/CONTRIBUTING.md#code-contribution and verify that this code contribution fits with the description. If yes, tell is in a comment.
This PR will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

Fix patch:
diff --git a/tpl/tplimpl/embedded/templates/schema.html b/tpl/tplimpl/embedded/templates/schema.html
index 8a55afe804e..c4e89abd6e9 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 -}}


Test patch:
diff --git a/hugolib/embedded_templates_test.go b/hugolib/embedded_templates_test.go
index a3b09e369e0..2f506d51419 100644
--- a/hugolib/embedded_templates_test.go
+++ b/hugolib/embedded_templates_test.go
@@ -70,9 +70,9 @@ title: My Site
 <meta property="article:published_time" content="2021-02-26T18:02:00-01:00" />
 <meta property="article:modified_time" content="2021-05-22T19:25:00-01:00" />
 <meta itemprop="name" content="My Bundle">
-<meta itemprop="image" content="https://example.org/mybundle/featured-sunset.jpg" />
-<meta itemprop="datePublished" content="2021-02-26T18:02:00-01:00" />
-<meta itemprop="dateModified" content="2021-05-22T19:25:00-01:00" />
+<meta itemprop="image" content="https://example.org/mybundle/featured-sunset.jpg">
+<meta itemprop="datePublished" content="2021-02-26T18:02:00-01:00">
+<meta itemprop="dateModified" content="2021-05-22T19:25:00-01:00">
 
 `)
 	b.AssertFileContent("public/mypage/index.html", `
@@ -83,17 +83,17 @@ title: My Site
 <meta property="og:image" content="https://example.org/mypage/sample.jpg" />
 <meta property="article:published_time" content="2021-02-26T18:02:00+01:00" />
 <meta property="article:modified_time" content="2021-05-22T19:25:00+01:00" />
-<meta itemprop="image" content="https://example.org/pageimg1.jpg" />
-<meta itemprop="image" content="https://example.org/pageimg2.jpg" />
-<meta itemprop="image" content="https://example.local/logo.png" />
-<meta itemprop="image" content="https://example.org/mypage/sample.jpg" />
-<meta itemprop="datePublished" content="2021-02-26T18:02:00+01:00" />
-<meta itemprop="dateModified" content="2021-05-22T19:25:00+01:00" />
+<meta itemprop="image" content="https://example.org/pageimg1.jpg">
+<meta itemprop="image" content="https://example.org/pageimg2.jpg">
+<meta itemprop="image" content="https://example.local/logo.png">
+<meta itemprop="image" content="https://example.org/mypage/sample.jpg">
+<meta itemprop="datePublished" content="2021-02-26T18:02:00+01:00">
+<meta itemprop="dateModified" content="2021-05-22T19:25:00+01:00">
 `)
 	b.AssertFileContent("public/mysite/index.html", `
 <meta name="twitter:image" content="https://example.org/siteimg1.jpg" />
 <meta property="og:image" content="https://example.org/siteimg1.jpg" />
-<meta itemprop="image" content="https://example.org/siteimg1.jpg" />
+<meta itemprop="image" content="https://example.org/siteimg1.jpg">
 `)
 }