Browse Source

fix structured data generation

main
Nicolas Massé 5 years ago
parent
commit
48adb949c8
  1. 40
      layouts/partials/head.html

40
layouts/partials/head.html

@ -56,6 +56,10 @@
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
<!--
-- Structured Data can be tested using the Google Search Console.
-- https://search.google.com/test/rich-results
-->
{{- if .IsHome }} {{- if .IsHome }}
<script type="application/ld+json"> <script type="application/ld+json">
{ {
@ -63,8 +67,8 @@
"@type": "WebSite", "@type": "WebSite",
"name": "{{ .Site.Title | safeJS }}", "name": "{{ .Site.Title | safeJS }}",
"url": "{{ .Site.BaseURL }}", "url": "{{ .Site.BaseURL }}",
"description": "{{ .Site.Params.subtitle | safeJS }}", "description": "{{ .Site.Params.subtitle }}",
"license": "Copyright {{ .Site.Home.Date.Year }} {{ .Site.Title | safeJS }}" "license": "Copyright {{ .Site.Home.Date.Year }} {{ .Site.Title }}"
} }
</script> </script>
{{ else if .IsPage -}} {{ else if .IsPage -}}
@ -73,36 +77,46 @@
"@context": "http://schema.org", "@context": "http://schema.org",
"@type": "BlogPosting", "@type": "BlogPosting",
"articleSection": "{{ .Section }}", "articleSection": "{{ .Section }}",
"name": "{{ .Title | safeJS }}", "name": "{{ .Title }}",
"headline": "{{ .Title | safeJS }}", "headline": "{{ .Title }}",
"description": "{{ if .Description }}{{ .Description | safeJS }}{{ else }}{{ if .IsPage }}{{ .Summary | plainify | htmlUnescape | safeJS }}{{ end }}{{ end }}", "description": "{{ if .Description }}{{ .Description }}{{ else }}{{ if .IsPage }}{{ .Summary | plainify | htmlUnescape }}{{ end }}{{ end }}",
"inLanguage": {{ .Site.LanguageCode | default "en-us" }}, {{- if and (eq .Lang "fr") (.Scratch.Get "en_article_in_fr_site") }}
"inLanguage": "en",
{{- else }}
"inLanguage": "{{ .Language.Lang }}",
{{- end }}
"isFamilyFriendly": "true", "isFamilyFriendly": "true",
"mainEntityOfPage": { "mainEntityOfPage": {
"@type": "WebPage", "@type": "WebPage",
{{- if .Scratch.Get "en_article_in_fr_site" -}}
{{- range first 1 .Translations }}
"@id": "{{ .Permalink }}" "@id": "{{ .Permalink }}"
{{- end -}}
{{- else }}
"@id": "{{ .Permalink }}"
{{- end }}
}, },
"author" : { "author" : {
"@type": "Person", "@type": "Person",
"name": "{{ .Site.Title | safeJS }}" "name": "{{ .Site.Title }}"
}, },
"creator" : { "creator" : {
"@type": "Person", "@type": "Person",
"name": "{{ .Site.Title | safeJS }}" "name": "{{ .Site.Title }}"
}, },
"accountablePerson" : { "accountablePerson" : {
"@type": "Person", "@type": "Person",
"name": "{{ .Site.Title | safeJS }}" "name": "{{ .Site.Title }}"
}, },
"copyrightHolder" : "{{ .Site.Title | safeJS }}", "copyrightHolder" : "{{ .Site.Title }}",
"copyrightYear" : "{{ .Site.Home.Date.Year }}", "copyrightYear" : "{{ .Site.Home.Date.Year }}",
"dateCreated": "{{ .Date.Format "2006-01-02T15:04:05.00Z" | safeHTML }}", "dateCreated": "{{ .Date.Format "2006-01-02T15:04:05.00Z" | safeHTML }}",
"datePublished": "{{ .PublishDate.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 }}", "dateModified": "{{ .Lastmod.Format "2006-01-02T15:04:05.00Z" | safeHTML }}",
"publisher":{ "publisher":{
"@type":"Person", "@type": "Person",
"name": {{ .Site.Title | safeJS }}, "name": "{{ .Site.Title }}",
"url": {{ .Site.BaseURL }} "url": "{{ .Site.BaseURL }}"
}, },
"url" : "{{ .Permalink }}", "url" : "{{ .Permalink }}",
"wordCount" : "{{ .WordCount }}" "wordCount" : "{{ .WordCount }}"

Loading…
Cancel
Save