From 1c3e19f6d6d9622b8ab6df94c94fe201e40e5f65 Mon Sep 17 00:00:00 2001 From: Nicolas MASSE Date: Tue, 5 Jan 2021 16:42:09 +0100 Subject: [PATCH] cleanup structured data --- layouts/partials/head.html | 87 ++++++++++++-------------------------- 1 file changed, 27 insertions(+), 60 deletions(-) diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 0b52325..fcb9c48 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -55,6 +55,8 @@ @@ -69,68 +71,33 @@ -- Structured Data can be tested using the Google Search Console. -- https://search.google.com/test/rich-results --> -{{- if .IsHome }} +{{- if .IsHome -}} + {{- $.Scratch.Set "structured_data" (dict "@context" "http://schema.org" "@type" "WebSite" "name" .Site.Title "url" .Site.BaseURL) -}} + {{- with .Site.Params.subtitle -}} + {{- $.Scratch.SetInMap "structured_data" "description" . -}} + {{- end -}} +{{- else if and .IsPage (eq .Section "blog") -}} + {{- $.Scratch.Set "structured_data" (dict "@context" "http://schema.org" "@type" "BlogPosting" "headline" .Title "image" (slice) "articleSection" .Section) -}} + {{- if and (eq .Lang "fr") (.Scratch.Get "en_article_in_fr_site") -}} + {{- $.Scratch.SetInMap "structured_data" "inLanguage" "en" -}} + {{- range first 1 .Translations -}} + {{- $.Scratch.SetInMap "structured_data" "mainEntityOfPage" (dict "@type" "WebPage" "@id" .Permalink) -}} + {{- end -}} + {{- else -}} + {{- $.Scratch.SetInMap "structured_data" "inLanguage" .Language.Lang -}} + {{- $.Scratch.SetInMap "structured_data" "mainEntityOfPage" (dict "@type" "WebPage" "@id" .Permalink) -}} + {{- end -}} + {{- if not .PublishDate.IsZero -}} + {{- $.Scratch.SetInMap "structured_data" "datePublished" .PublishDate -}} + {{- end -}} + {{- if and (not .Lastmod.IsZero) (ne .Lastmod .PublishDate) -}} + {{- $.Scratch.SetInMap "structured_data" "dateModified" .Lastmod -}} + {{- end -}} +{{- end -}} +{{- with $.Scratch.Get "structured_data" }} -{{ else if .IsPage -}} - -{{ end -}}