Browse Source

cleanup structured data

main
Nicolas Massé 5 years ago
parent
commit
1c3e19f6d6
  1. 87
      layouts/partials/head.html

87
layouts/partials/head.html

@ -55,6 +55,8 @@
<!--
-- It's an english article published in the french site
-- Tell Google not to index it and link to the original article.
--
-- See https://developers.google.com/search/docs/advanced/crawling/consolidate-duplicate-urls
-->
<link rel="canonical" href="{{ .Permalink }}">
<meta name="robots" content="noindex">
@ -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" }}
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"name": "{{ .Site.Title | safeJS }}",
"url": "{{ .Site.BaseURL }}",
"description": "{{ .Site.Params.subtitle }}",
"license": "Copyright {{ .Site.Home.Date.Year }} {{ .Site.Title }}"
}
{{- . | jsonify | safeJS -}}
</script>
{{ else if .IsPage -}}
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BlogPosting",
"articleSection": "{{ .Section }}",
"name": "{{ .Title }}",
"headline": "{{ .Title }}",
"description": "{{ if .Description }}{{ .Description }}{{ else }}{{ if .IsPage }}{{ .Summary | plainify | htmlUnescape }}{{ end }}{{ end }}",
{{- if and (eq .Lang "fr") (.Scratch.Get "en_article_in_fr_site") }}
"inLanguage": "en",
{{- else }}
"inLanguage": "{{ .Language.Lang }}",
{{- end }}
"isFamilyFriendly": "true",
"mainEntityOfPage": {
"@type": "WebPage",
{{- if .Scratch.Get "en_article_in_fr_site" -}}
{{- range first 1 .Translations }}
"@id": "{{ .Permalink }}"
{{- end -}}
{{- else }}
"@id": "{{ .Permalink }}"
{{- end }}
},
"author" : {
"@type": "Person",
"name": "{{ .Site.Title }}"
},
"creator" : {
"@type": "Person",
"name": "{{ .Site.Title }}"
},
"accountablePerson" : {
"@type": "Person",
"name": "{{ .Site.Title }}"
},
"copyrightHolder" : "{{ .Site.Title }}",
"copyrightYear" : "{{ .Site.Home.Date.Year }}",
"dateCreated": "{{ .Date.Format "2006-01-02T15:04:05.00Z" | safeHTML }}",
"datePublished": "{{ .PublishDate.Format "2006-01-02T15:04:05.00Z" | safeHTML }}",
"dateModified": "{{ .Lastmod.Format "2006-01-02T15:04:05.00Z" | safeHTML }}",
"publisher":{
"@type": "Person",
"name": "{{ .Site.Title }}",
"url": "{{ .Site.BaseURL }}"
},
"url" : "{{ .Permalink }}",
"wordCount" : "{{ .WordCount }}"
}
</script>
{{ end -}}
</head>

Loading…
Cancel
Save