From e2ccfe8bf324e9d459c8364442d0e9a5435e2400 Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Fri, 24 Mar 2017 16:49:26 +0200 Subject: [PATCH] Clean up empty whitespace in JSON-LD Use secret formatting feature of Go templates, adding - to blocks to clear whitespace around the tags. --- layouts/_default/list.html | 18 +++++++++--------- layouts/_default/single.html | 26 +++++++++++++------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/layouts/_default/list.html b/layouts/_default/list.html index e12a0ec..b9d9605 100644 --- a/layouts/_default/list.html +++ b/layouts/_default/list.html @@ -3,26 +3,26 @@ { "@context": "http://schema.org", "@type": "Blog", - {{/* Google recommends the headline be no more than 110 characters */}} + {{- /* Google recommends the headline be no more than 110 characters */}} "headline": "{{ substr .Site.Title 0 110 }}", "url" : "{{ printf "%s" .Permalink }}", "author": { "@type": "Person", "name": "{{ .Site.Params.author }}" }, - {{ $ISO8601 := "2006-01-02T15:04:05-07:00" }} - {{ if not .Date.IsZero }} + {{- $ISO8601 := "2006-01-02T15:04:05-07:00" }} + {{- if not .Date.IsZero }} "dateModified": "{{ .Date.Format $ISO8601 }}", - {{ end }} - {{ with .Site.Social.GooglePlus }} + {{- end }} + {{- with .Site.Social.GooglePlus }} "publisher": "{{ printf "%s" . }}", - {{ end }} - {{/* all of the site's categories/tags, from Hugo's tpl/template_embedded.go */}} + {{- end }} + {{- /* all of the site's categories/tags, from Hugo's tpl/template_embedded.go */}} "keywords": "{{ range $plural, $terms := .Site.Taxonomies }}{{ range $term, $val := $terms }}{{ printf "%s," $term }}{{ end }}{{ end }}" - {{ with .Site.Params.description }} + {{- with .Site.Params.description -}} , "description": "{{- . -}}" - {{ end }} + {{- end }} } {{ end }} diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 883dd9c..d40cda0 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -5,7 +5,7 @@ { "@context": "http://schema.org", "@type": "BlogPosting", - {{/* Google recommends the headline be no more than 110 characters */}} + {{- /* Google recommends the headline be no more than 110 characters */}} "headline": "{{ substr .Title 0 110 }}", {{- with .Params.images -}}{{ range first 1 . }} "image": { @@ -17,37 +17,37 @@ , "height": "{{ .Height }}", "width": "{{ .Width }}" - {{ end }} + {{- end -}} {{ end }} }, {{- end -}}{{ end }} "url": "{{ printf "%s" .Permalink }}", "wordCount": "{{ .WordCount }}", - {{ $ISO8601 := "2006-01-02T15:04:05-07:00" }} - {{ if not .PublishDate.IsZero }} + {{- $ISO8601 := "2006-01-02T15:04:05-07:00" }} + {{- if not .PublishDate.IsZero }} "datePublished": "{{ .PublishDate.Format $ISO8601 }}", - {{ else }} + {{- else }} "datePublished": "{{ .Date.Format $ISO8601 }}", - {{ end }} - {{ if not .Lastmod.IsZero }} + {{- end }} + {{- if not .Lastmod.IsZero }} "dateModified": "{{ .Lastmod.Format $ISO8601 }}", - {{ end }} - {{ with .Site.Social.GooglePlus }} + {{- end }} + {{- with .Site.Social.GooglePlus }} "publisher": "{{ printf "%s" . }}", - {{ end }} + {{- end }} "author": { "@type": "Person", "name": "{{ .Params.author | default .Site.Params.author }}" } - {{ if or (.Params.categories) (.Params.tags) }} + {{- if or (.Params.categories) (.Params.tags) -}} , "keywords": "{{ with .Params.categories }}{{ range $i, $e := . }}{{ if $i }},{{ end }}{{ $e }}{{ end }},{{ end }}{{ with .Params.tags }}{{ range $i, $e := . }}{{ if $i }},{{ end }}{{ $e }}{{ end }}{{ end }}" - {{ end }} + {{- end }} {{- with .Params.description -}} , "description": "{{ . }}" - {{ end }} + {{- end }} }