Compare commits

...

3 commits

Author SHA1 Message Date
Joe Mooring 22211d936d
Merge 60cb848459 into 74ce5dc841 2024-03-28 07:15:18 -07:00
Joe Mooring 74ce5dc841 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>
2024-03-28 14:56:02 +01:00
Joe Mooring 60cb848459 tpl/tplimpl: Update RSS template
- Use publication date for pubdate
- Include version in generator element

Closes #3918
Closes #11692
2024-03-23 13:59:13 -07:00
3 changed files with 65 additions and 26 deletions

View file

@ -68,9 +68,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", `
@ -81,17 +81,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">
`)
}

View file

@ -48,7 +48,7 @@
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{ . }} on {{ end }}{{ .Site.Title }}{{ end }}</title>
<link>{{ .Permalink }}</link>
<description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{ . }} {{ end }}{{ end }}on {{ .Site.Title }}</description>
<generator>Hugo -- gohugo.io</generator>
<generator>Hugo {{ hugo.Version }}</generator>
<language>{{ site.Language.LanguageCode }}</language>{{ with $authorEmail }}
<managingEditor>{{.}}{{ with $authorName }} ({{ . }}){{ end }}</managingEditor>{{ end }}{{ with $authorEmail }}
<webMaster>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</webMaster>{{ end }}{{ with .Site.Copyright }}
@ -61,7 +61,7 @@
<item>
<title>{{ .Title }}</title>
<link>{{ .Permalink }}</link>
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
<pubDate>{{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>
{{- with $authorEmail }}<author>{{ . }}{{ with $authorName }} ({{ . }}){{ end }}</author>{{ end }}
<guid>{{ .Permalink }}</guid>
<description>{{ .Summary | transform.XMLEscape | safeHTML }}</description>

View file

@ -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 }}">
{{- with or .Title site.Title }}
<meta itemprop="name" content="{{ . }}">
{{- 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 }}">
{{- with or .Description .Summary site.Params.Description }}
<meta itemprop="description" content="{{ . }}">
{{- end }}
{{- $images := partial "_funcs/get-page-images" . -}}
{{- range first 6 $images -}}
<meta itemprop="image" content="{{ .Permalink }}" />
{{- end -}}
<!-- 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 }}" />
{{- $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.
*/}}
{{- $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 -}}