mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Use .Date.IsZero to skip unset date in embedded templates
Use `{{ if not .Date.IsZero }}` to print dates only when they are defined. This is to avoid things like <lastBuildDate>Mon, 01 Jan 0001 00:00:00 +0000</lastBuildDate> and <lastmod>0001-01-01T00:00:00+00:00</lastmod> showing up in index.xml (RSS) and sitemap.xml. Pipe dates with ±hh:mm time zone through `safeHtml` to prevent the `+` sign from turning into `+`. Also make some shuffling to avoid blank lines in the output.
This commit is contained in:
parent
35684e8f6f
commit
3d60955e17
1 changed files with 13 additions and 13 deletions
|
@ -50,18 +50,18 @@ func (t *GoHtmlTemplate) EmbedTemplates() {
|
||||||
<title>{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}</title>
|
<title>{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}</title>
|
||||||
<link>{{ .Permalink }}</link>
|
<link>{{ .Permalink }}</link>
|
||||||
<description>Recent content {{ with .Title }}in {{.}} {{ end }}on {{ .Site.Title }}</description>
|
<description>Recent content {{ with .Title }}in {{.}} {{ end }}on {{ .Site.Title }}</description>
|
||||||
<generator>Hugo -- gohugo.io</generator>
|
<generator>Hugo -- gohugo.io</generator>{{ with .Site.LanguageCode }}
|
||||||
{{ with .Site.LanguageCode }}<language>{{.}}</language>{{end}}
|
<language>{{.}}</language>{{end}}{{ with .Site.Author.email }}
|
||||||
{{ with .Site.Author.email }}<managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}
|
<managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with .Site.Author.email }}
|
||||||
{{ with .Site.Author.email }}<webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}
|
<webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with .Site.Copyright }}
|
||||||
{{ with .Site.Copyright }}<copyright>{{.}}</copyright>{{end}}
|
<copyright>{{.}}</copyright>{{end}}{{ if not .Date.IsZero }}
|
||||||
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</lastBuildDate>
|
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHtml }}</lastBuildDate>{{ end }}
|
||||||
<atom:link href="{{.Url}}" rel="self" type="application/rss+xml" />
|
<atom:link href="{{.Url}}" rel="self" type="application/rss+xml" />
|
||||||
{{ range first 15 .Data.Pages }}
|
{{ range first 15 .Data.Pages }}
|
||||||
<item>
|
<item>
|
||||||
<title>{{ .Title }}</title>
|
<title>{{ .Title }}</title>
|
||||||
<link>{{ .Permalink }}</link>
|
<link>{{ .Permalink }}</link>
|
||||||
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</pubDate>
|
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHtml }}</pubDate>
|
||||||
{{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}
|
{{ with .Site.Author.email }}<author>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</author>{{end}}
|
||||||
<guid>{{ .Permalink }}</guid>
|
<guid>{{ .Permalink }}</guid>
|
||||||
<description>{{ .Content | html }}</description>
|
<description>{{ .Content | html }}</description>
|
||||||
|
@ -73,8 +73,8 @@ func (t *GoHtmlTemplate) EmbedTemplates() {
|
||||||
t.AddInternalTemplate("_default", "sitemap.xml", `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
t.AddInternalTemplate("_default", "sitemap.xml", `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
{{ range .Data.Pages }}
|
{{ range .Data.Pages }}
|
||||||
<url>
|
<url>
|
||||||
<loc>{{ .Permalink }}</loc>
|
<loc>{{ .Permalink }}</loc>{{ if not .Date.IsZero }}
|
||||||
<lastmod>{{ safeHtml ( .Date.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ with .Sitemap.ChangeFreq }}
|
<lastmod>{{ safeHtml ( .Date.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
|
||||||
<changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
|
<changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
|
||||||
<priority>{{ .Sitemap.Priority }}</priority>{{ end }}
|
<priority>{{ .Sitemap.Priority }}</priority>{{ end }}
|
||||||
</url>
|
</url>
|
||||||
|
@ -134,7 +134,7 @@ func (t *GoHtmlTemplate) EmbedTemplates() {
|
||||||
<meta property="og:image" content="{{ . }}" />
|
<meta property="og:image" content="{{ . }}" />
|
||||||
{{ end }}{{ end }}
|
{{ end }}{{ end }}
|
||||||
|
|
||||||
<meta property="og:updated_time" content="{{ .Date.Format "2006-01-02T15:04:05-07:00" }}"/>{{ with .Params.audio }}
|
<meta property="og:updated_time" content="{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHtml }}"/>{{ with .Params.audio }}
|
||||||
<meta property="og:audio" content="{{ . }}" />{{ end }}{{ with .Params.locale }}
|
<meta property="og:audio" content="{{ . }}" />{{ end }}{{ with .Params.locale }}
|
||||||
<meta property="og:locale" content="{{ . }}" />{{ end }}{{ with .Site.Params.title }}
|
<meta property="og:locale" content="{{ . }}" />{{ end }}{{ with .Site.Params.title }}
|
||||||
<meta property="og:site_name" content="{{ . }}" />{{ end }}{{ with .Params.videos }}
|
<meta property="og:site_name" content="{{ . }}" />{{ end }}{{ with .Params.videos }}
|
||||||
|
@ -192,9 +192,9 @@ func (t *GoHtmlTemplate) EmbedTemplates() {
|
||||||
<meta itemprop="name" content="{{ .Title }}">
|
<meta itemprop="name" content="{{ .Title }}">
|
||||||
<meta itemprop="description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ end }}{{ end }}">
|
<meta itemprop="description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ end }}{{ end }}">
|
||||||
|
|
||||||
{{if .IsPage}}{{ $ISO8601 := "2006-01-02T15:04:05-07:00" }}{{ if ne (.PublishDate.Format $ISO8601) "0001-01-01T00:00:00+00:00" }}
|
{{if .IsPage}}{{ $ISO8601 := "2006-01-02T15:04:05-07:00" }}{{ if not .PublishDate.IsZero }}
|
||||||
<meta itemprop="datePublished" content="{{ .PublishDate.Format $ISO8601 }}" />{{ end }}
|
<meta itemprop="datePublished" content="{{ .PublishDate.Format $ISO8601 | safeHtml }}" />{{ end }}
|
||||||
<meta itemprop="dateModified" content="{{ .Date.Format $ISO8601 }}" />
|
<meta itemprop="dateModified" content="{{ .Date.Format $ISO8601 | safeHtml }}" />
|
||||||
<meta itemprop="wordCount" content="{{ .WordCount }}">
|
<meta itemprop="wordCount" content="{{ .WordCount }}">
|
||||||
{{ with .Params.images }}{{ range first 6 . }}
|
{{ with .Params.images }}{{ range first 6 . }}
|
||||||
<meta itemprop="image" content="{{ . }}">
|
<meta itemprop="image" content="{{ . }}">
|
||||||
|
|
Loading…
Reference in a new issue