▾ added blog/layouts/partials/jsonld.html +43 -0 Viewed
new file mode 100644 @@ -0,0 +1,43 @@ 1 + {{- /* 2 + JSON-LD structured data - BlogPosting for a post, WebSite for home/section 3 + pages, so a search engine gets headline/author/dates/image without having 4 + to infer them from the markup. Takes the same (page, desc, image) shape as 5 + opengraph.html; `image` is page-image.html's own dict so the two don't 6 + compute it twice and can't disagree on it. 7 + */ -}} 8 + {{- $page := .page }} 9 + {{- $desc := .desc }} 10 + {{- $image := .image }} 11 + {{- $author := site.Params.profile }} 12 + {{- $authorName := "" }} 13 + {{- with $author }} 14 + {{- $authorName = strings.TrimSpace (printf "%s %s" .firstName .lastName) }} 15 + {{- end }} 16 + 17 + {{- $data := dict 18 + "@context" "https://schema.org" 19 + "url" $page.Permalink 20 + "inLanguage" site.Language.Lang 21 + }} 22 + {{- with $desc }}{{ $data = merge $data (dict "description" .) }}{{ end }} 23 + {{- with $image.url }}{{ $data = merge $data (dict "image" .) }}{{ end }} 24 + 25 + {{- if $page.IsPage }} 26 + {{- $data = merge $data (dict 27 + "@type" "BlogPosting" 28 + "headline" $page.Title 29 + "datePublished" ($page.Date.Format "2006-01-02T15:04:05Z07:00") 30 + "dateModified" ($page.Lastmod.Format "2006-01-02T15:04:05Z07:00") 31 + "mainEntityOfPage" (dict "@type" "WebPage" "@id" $page.Permalink) 32 + ) }} 33 + {{- with $authorName }} 34 + {{- $data = merge $data (dict "author" (dict "@type" "Person" "name" .) "publisher" (dict "@type" "Person" "name" .)) }} 35 + {{- end }} 36 + {{- else }} 37 + {{- $data = merge $data (dict 38 + "@type" "WebSite" 39 + "name" site.Title 40 + ) }} 41 + {{- end }} 42 + 43 + < script type = "application/ld+json" > { { $data | jsonify ( dict "indent" " " ) | safeJS } } < / script >
new file mode 100644 @@ -0,0 +1,43 @@ 1 + {{- /* 2 + JSON-LD structured data - BlogPosting for a post, WebSite for home/section 3 + pages, so a search engine gets headline/author/dates/image without having 4 + to infer them from the markup. Takes the same (page, desc, image) shape as 5 + opengraph.html; `image` is page-image.html's own dict so the two don't 6 + compute it twice and can't disagree on it. 7 + */ -}} 8 + {{- $page := .page }} 9 + {{- $desc := .desc }} 10 + {{- $image := .image }} 11 + {{- $author := site.Params.profile }} 12 + {{- $authorName := "" }} 13 + {{- with $author }} 14 + {{- $authorName = strings.TrimSpace (printf "%s %s" .firstName .lastName) }} 15 + {{- end }} 16 + 17 + {{- $data := dict 18 + "@context" "https://schema.org" 19 + "url" $page.Permalink 20 + "inLanguage" site.Language.Lang 21 + }} 22 + {{- with $desc }}{{ $data = merge $data (dict "description" .) }}{{ end }} 23 + {{- with $image.url }}{{ $data = merge $data (dict "image" .) }}{{ end }} 24 + 25 + {{- if $page.IsPage }} 26 + {{- $data = merge $data (dict 27 + "@type" "BlogPosting" 28 + "headline" $page.Title 29 + "datePublished" ($page.Date.Format "2006-01-02T15:04:05Z07:00") 30 + "dateModified" ($page.Lastmod.Format "2006-01-02T15:04:05Z07:00") 31 + "mainEntityOfPage" (dict "@type" "WebPage" "@id" $page.Permalink) 32 + ) }} 33 + {{- with $authorName }} 34 + {{- $data = merge $data (dict "author" (dict "@type" "Person" "name" .) "publisher" (dict "@type" "Person" "name" .)) }} 35 + {{- end }} 36 + {{- else }} 37 + {{- $data = merge $data (dict 38 + "@type" "WebSite" 39 + "name" site.Title 40 + ) }} 41 + {{- end }} 42 + 43 + < script type = "application/ld+json" > { { $data | jsonify ( dict "indent" " " ) | safeJS } } < / script >