Skip to content

Commit

Permalink
layouts: Fix more structured data escaping issues
Browse files Browse the repository at this point in the history
I think we actually only need to quote string literals. Otherwise,
it seems that Hugo automatically adds quoting for us, and doesn't
use funny escaping of URLs, special characters, etc.
  • Loading branch information
alanorth committed Mar 19, 2020
1 parent 9e0b000 commit 85abd20
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions layouts/_default/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"@context": "http://schema.org",
"@type": "Blog",
{{- /* Google recommends the headline be no more than 110 characters */}}
"headline": "{{ substr .Site.Title 0 110 }}",
"url" : "{{ printf "%s" .Permalink }}",
"headline": {{ substr .Site.Title 0 110 }},
"url" : {{ printf "%s" .Permalink }},
"author": {
"@type": "Person",
"name": "{{ .Site.Params.author }}"
"name": {{ .Site.Params.author }}
},
{{- $ISO8601 := "2006-01-02T15:04:05-07:00" }}
{{- if not .Date.IsZero }}
Expand Down
8 changes: 4 additions & 4 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"@context": "http://schema.org",
"@type": "BlogPosting",
{{- /* Google recommends the headline be no more than 110 characters */}}
"headline": "{{ substr .Title 0 110 }}",
"headline": {{ substr .Title 0 110 }},
{{- with .Params.images -}}{{ range first 1 . }}
"image": {
"@type": "ImageObject",
"url": "{{ . | absURL }}"
"url": {{ . | absURL }}
{{- /* Don't try to get imageConfig if image param is not local */ -}}
{{- if not (or (hasPrefix . "http://") (hasPrefix . "https://")) -}}
{{- with (imageConfig (printf "/static/%s" .)) -}}
Expand All @@ -21,7 +21,7 @@
{{ end }}
},
{{- end -}}{{ end }}
"url": "{{ printf "%s" .Permalink }}",
"url": {{ printf "%s" .Permalink }},
"wordCount": "{{ .WordCount }}",
{{- $ISO8601 := "2006-01-02T15:04:05-07:00" }}
{{- if not .PublishDate.IsZero }}
Expand All @@ -34,7 +34,7 @@
{{- end }}
"author": {
"@type": "Person",
"name": "{{ .Params.author | default .Site.Params.author }}"
"name": {{ .Params.author | default .Site.Params.author }}
}
{{- if or (.Params.keywords) (or (.Params.categories) (.Params.tags)) -}}
,
Expand Down

2 comments on commit 85abd20

@fte378
Copy link
Contributor

@fte378 fte378 commented on 85abd20 Mar 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. I had issues with this for months.

@alanorth
Copy link
Owner Author

@alanorth alanorth commented on 85abd20 Mar 19, 2020 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.