I had a partial template that I use to print some schema data for SEO purposes, it looks like this:
<script type="application/ld+json">
{{/* Generate our vars */}}
{{- if .IsHome -}}
{{- $.Scratch.Set "schematype" "website" -}}
{{- else -}}
{{- $.Scratch.Set "schematype" "Article" -}}
{{- end -}}
{{- $.Scratch.SetInMap "schema" "@context" "https://schema.org" -}}
<!-- Post type //-->
{{- $.Scratch.SetInMap "schema" "@type" ( $.Scratch.Get "schematype" ) -}}
<!-- Page Details //-->
{{- $.Scratch.SetInMap "schema" "url" .Permalink -}}
{{- $.Scratch.SetInMap "schema" "mainEntityOfPage" ( dict "@type" "WebPage" "@id" .Site.BaseURL ) -}}
<!-- Publisher Details //-->
{{- with (imageConfig ( printf "static/%s" .Site.Params.logo )) -}}
{{- $.Scratch.Add "publisherImageWidth" ( int .Width ) -}}
{{- $.Scratch.Add "publisherImageHeight" ( int .Height ) -}}
{{- end -}}
{{- $.Scratch.SetInMap "schema" "publisher" ( dict "@type" "Organization" "name" .Site.Author.james.name "sameAs" .Site.Author.james.social "logo" ( dict "@type" "ImageObject" "url" ( .Site.Params.logo | absURL ) "width" ($.Scratch.Get "publisherImageWidth") "height" ($.Scratch.Get "publisherImageHeight"))) -}}
{{- if .IsPage -}}
<!-- Post Author //-->
<!-- Get author image size -->
{{- with (imageConfig ( printf "static/%s" .Site.Author.james.image )) -}}
{{- $.Scratch.Add "authorImageWidth" ( int .Width ) -}}
{{- $.Scratch.Add "authorImageHeight" ( int .Height ) -}}
{{- end -}}
{{- $.Scratch.SetInMap "schema" "author" ( dict "@type" "Person" "name" .Site.Author.james.name "sameAs" .Site.Author.james.social "description" .Site.Author.james.description "image" (dict "@type" "ImageObject" "url" ( .Site.Author.james.image | absURL ) "height" ($.Scratch.Get "authorImageHeight") "width" ($.Scratch.Get "authorImageWidth" ) ) "url" "https://jloh.co/author/james/" ) -}}
<!-- Post details //-->
<!-- TODO: Look at unescaping this?? //-->
{{- $.Scratch.SetInMap "schema" "headline" .Title -}}
{{- $.Scratch.SetInMap "schema" "datePublished" ( .Date.Format "2006-01-02T15:04:05-07:00" ) -}}
{{- if .Lastmod -}}
{{- $.Scratch.SetInMap "schema" "dateModified" ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) -}}
{{- end -}}
{{- with .Params.tags -}}
{{- $.Scratch.SetInMap "schema" "keywords" (delimit . ", " ) -}}
{{- end -}}
{{- with .Params.cover_image -}}
{{- with (imageConfig ( printf "static/%s" . )) -}}
{{- $.Scratch.Add "coverImageWidth" ( int .Width ) -}}
{{- $.Scratch.Add "coverImageHeight" (int .Height ) -}}
{{- end -}}
{{- $.Scratch.SetInMap "schema" "image" ( dict "@type" "ImageObject" "url" ( . | absURL) "width" ($.Scratch.Get "coverImageWidth") "height" ($.Scratch.Get "coverImageHeight")) -}}
{{- end -}}
{{- end -}}
{{- $.Scratch.SetInMap "schema" "description" "Description" -}}
<!-- Generate schema //-->
{{- $.Scratch.Get "schema" | jsonify -}}
</script>
Its included via a block in the single.html template:
{{- define "header" -}}
{{ partial "schema" . }}
{{- end -}}
And rendered like this in v0.54 (I’ve prettified it to make it a bit nicer to read, otherwise the JSON is just in a big blob)
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Article",
"author": {
"@type": "Person",
"description": "Sysadmin for a web solutions company deploying cloud solutions across the globe",
"image": {
"@type": "ImageObject",
"height": 1130,
"url": "http://localhost:62435/images/2017/08/jimmy.jpg",
"width": 1000
},
"name": "James Loh",
"sameAs": [
"https://jloh.co",
"https://github.com/jloh",
"https://twitter.com/itsjloh"
],
"url": "https://jloh.co/author/james/"
},
"dateModified": "2019-01-26T15:43:00+11:00",
"datePublished": "2019-01-26T15:43:00+11:00",
"description": "Description",
"headline": "GeoJS gets a 2018 overhaul",
"keywords": "GeoJS, Projects",
"mainEntityOfPage": {
"@id": "http://localhost:62435/",
"@type": "WebPage"
},
"publisher": {
"@type": "Organization",
"logo": {
"@type": "ImageObject",
"height": 384,
"url": "http://localhost:62435/images/2017/08/android-chrome-192x192-jloh-1.png",
"width": 384
},
"name": "James Loh",
"sameAs": [
"https://jloh.co",
"https://github.com/jloh",
"https://twitter.com/itsjloh"
]
},
"url": "http://localhost:62435/posts/geojs-2018-overhaul/"
}
</script>
In v0.55 however the partial is completely busted and ends up rendered this like:
<script type="application/ld+json">
""""<!-- Post type
<!-- Get author image size -->""""""<!-- Post details
<!-- TODO: Look at unescaping this?? </script>
I’ve fixed it by changing the include to be like this:
{{- define "header" -}}
<script type="application/ld+json">
{{- partial "schema" . | safeJS -}}
</script>
{{- end -}}
And removed any HTML (comments, scripts etc) so that they’re outside of the template. This now renders it as expected like how it was in v0.55:
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"Article","dateModified":"2019-01-26T15:43:00+11:00","datePublished":"2019-01-26T15:43:00+11:00","description":"Description","headline":"GeoJS gets a 2018 overhaul","keywords":"GeoJS, Projects","mainEntityOfPage":{"@id":"http://localhost:1313/","@type":"WebPage"},"publisher":{"@type":"Organization","logo":{"@type":"ImageObject","height":192,"url":"http://localhost:1313/images/2017/08/android-chrome-192x192-jloh-1.png","width":192},"name":"James Loh","sameAs":["https://jloh.co","https://github.com/jloh","https://twitter.com/itsjloh"]},"url":"http://localhost:1313/posts/geojs-2018-overhaul/"}</script>
Just posting because I’m unsure whether this change was expected and in case it helps anyone else!