Fix date format in schema and opengraph templates
authorJoe Mooring <joe.mooring@veriphor.com>
Sun, 20 Jun 2021 19:30:41 +0000 (12:30 -0700)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 29 Jun 2021 18:20:38 +0000 (20:20 +0200)
Fixes #8671

hugolib/embedded_templates_test.go
tpl/tplimpl/embedded/templates.autogen.go
tpl/tplimpl/embedded/templates/opengraph.html
tpl/tplimpl/embedded/templates/schema.html

index 5d7d6dc2347330ef32683e0db4ece59f67709378..f0fc9cfdee3677c2a7db95cd0a35bbf27d6916eb 100644 (file)
@@ -31,12 +31,16 @@ images=["siteimg1.jpg", "siteimg2.jpg"]
 
        b.WithContent("mybundle/index.md", `---
 title: My Bundle
+date: 2021-02-26T18:02:00-01:00
+lastmod: 2021-05-22T19:25:00-01:00
 ---
 `)
 
        b.WithContent("mypage.md", `---
 title: My Page
 images: ["pageimg1.jpg", "pageimg2.jpg"]
+date: 2021-02-26T18:02:00+01:00
+lastmod: 2021-05-22T19:25:00+01:00
 ---
 `)
 
@@ -62,16 +66,24 @@ title: My Site
 <meta property="og:title" content="My Bundle" />
 <meta property="og:url" content="https://example.org/mybundle/" />
 <meta property="og:image" content="https://example.org/mybundle/featured-sunset.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="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" />
 
 `)
        b.AssertFileContent("public/mypage/index.html", `
 <meta name="twitter:image" content="https://example.org/pageimg1.jpg"/>
 <meta property="og:image" content="https://example.org/pageimg1.jpg" />
 <meta property="og:image" content="https://example.org/pageimg2.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.org/pageimg2.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"/>
index cd706f8e1034f41221be3cefda53220165fd3615..b906f10d295baca9afd332cbcc33653bc618b460 100644 (file)
@@ -224,8 +224,8 @@ if (!doNotTrack) {
 {{- if .IsPage }}
 {{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
 <meta property="article:section" content="{{ .Section }}" />
-{{ with .PublishDate }}<meta property="article:published_time" content="{{ .Format $iso8601 }}" />{{ end }}
-{{ with .Lastmod }}<meta property="article:modified_time" content="{{ .Format $iso8601 }}" />{{ end }}
+{{ with .PublishDate }}<meta property="article:published_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end }}
+{{ with .Lastmod }}<meta property="article:modified_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end }}
 {{- end -}}
 
 {{- with .Params.audio }}<meta property="og:audio" content="{{ . }}" />{{ end }}
@@ -408,8 +408,8 @@ if (!doNotTrack) {
 
 {{- if .IsPage -}}
 {{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
-{{ with .PublishDate }}<meta itemprop="datePublished" content="{{ .Format $iso8601 }}" />{{ end}}
-{{ with .Lastmod }}<meta itemprop="dateModified" content="{{ .Format $iso8601 }}" />{{ end}}
+{{ 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 $.Params.images -}}
index b0395ae2f6085a67b09162e6a63bc2e2489ad950..e3961524b9d687ad7ece38e55e67c361360ad13a 100644 (file)
@@ -19,8 +19,8 @@
 {{- if .IsPage }}
 {{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
 <meta property="article:section" content="{{ .Section }}" />
-{{ with .PublishDate }}<meta property="article:published_time" content="{{ .Format $iso8601 }}" />{{ end }}
-{{ with .Lastmod }}<meta property="article:modified_time" content="{{ .Format $iso8601 }}" />{{ end }}
+{{ with .PublishDate }}<meta property="article:published_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end }}
+{{ with .Lastmod }}<meta property="article:modified_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end }}
 {{- end -}}
 
 {{- with .Params.audio }}<meta property="og:audio" content="{{ . }}" />{{ end }}
index 772c6c2b19df1123efe8e56325c541e0e537e72b..20b477b592d45acc3ec89162150f992df8caa864 100644 (file)
@@ -3,8 +3,8 @@
 
 {{- if .IsPage -}}
 {{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
-{{ with .PublishDate }}<meta itemprop="datePublished" content="{{ .Format $iso8601 }}" />{{ end}}
-{{ with .Lastmod }}<meta itemprop="dateModified" content="{{ .Format $iso8601 }}" />{{ end}}
+{{ 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 $.Params.images -}}