The plus sign in timestamp is represented as +
when using internal schema template. Despite it is piped through safeHTML
. I’ve also tried safeHTMLAttr
- same thing. Setting
markup:
goldmark:
renderer:
unsafe: true
doesn’t help either. On Hugo website, though, the date is displayed correctly:
<meta itemprop=dateModified content="2020-06-02T18:08:17+02:00">
I’m out of ideas. How should this be fixed?
The internal schema template is flawed. I’ll submit a PR later today.
In the interim…
layouts/partials/schema.html:
<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" }}{{ if not .PublishDate.IsZero }}
<meta itemprop="datePublished" {{ printf `content="%s"` (.PublishDate.Format $ISO8601) | safeHTMLAttr }} />{{ end }}
{{ if not .Lastmod.IsZero }}<meta itemprop="dateModified" {{ printf `content="%s"` (.Lastmod.Format $ISO8601) | safeHTMLAttr }} />{{ end }}
<meta itemprop="wordCount" content="{{ .WordCount }}">
{{ with $.Params.images }}{{ range first 6 . -}}
<meta itemprop="image" content="{{ . | absURL }}">
{{ end }}{{ else -}}
{{- $images := $.Resources.ByType "image" -}}
{{- $featured := $images.GetMatch "*feature*" -}}
{{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}}
{{- with $featured -}}
<meta itemprop="image" content="{{ $featured.Permalink }}">
{{ else -}}
{{- with $.Site.Params.images -}}
<meta itemprop="image" content="{{ index . 0 | absURL }}"/>
{{ end }}{{ end }}{{ 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 }}" />
{{- end }}
layouts/_default/baseof.html:
{{- partial "schema.html" . -}}
1 Like
Thanks, but safeHTMLAttr
didn’t work, or are there any other changes?
I’m actually rewriting the whole thing. My interim solution is just to ditch the timezone entirely. It will show the time in the future for two hours, but is standard-compliant at leset.
Look carefully at how safeHTMLAttr
is used in the code I posted.
1 Like
Thanks a lot. Looking carefully was the solution indeed!
system
Closed
July 21, 2020, 2:54pm
6
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.