Gestion du JSON-LD
This commit is contained in:
139
layouts/partials/head/json-ld.html
Normal file
139
layouts/partials/head/json-ld.html
Normal file
@@ -0,0 +1,139 @@
|
||||
{{- $noindex := partial "seo/noindex.html" . -}}
|
||||
{{- if not $noindex -}}
|
||||
{{- $language := site.LanguageCode | default site.Language.LanguageCode | default "fr-FR" -}}
|
||||
{{- $description := partial "head/description.html" . -}}
|
||||
{{- $pageClassification := partial "seo/page-classification.html" . -}}
|
||||
{{- $websiteID := printf "%s#website" site.Home.Permalink -}}
|
||||
{{- $author := partial "seo/person.html" . -}}
|
||||
{{- $authorID := index $author "@id" -}}
|
||||
{{- $website := dict
|
||||
"@type" "WebSite"
|
||||
"@id" $websiteID
|
||||
"url" site.Home.Permalink
|
||||
"name" site.Title
|
||||
"inLanguage" $language
|
||||
"author" (dict "@id" $authorID)
|
||||
-}}
|
||||
{{- with site.Params.description -}}
|
||||
{{- $website = merge $website (dict "description" .) -}}
|
||||
{{- end -}}
|
||||
{{- with site.Params.search -}}
|
||||
{{- with .action -}}
|
||||
{{- $searchURL := . | absURL -}}
|
||||
{{- $searchParam := $.Site.Params.search.param | default "q" -}}
|
||||
{{- $website = merge $website (dict
|
||||
"potentialAction" (dict
|
||||
"@type" "SearchAction"
|
||||
"target" (printf "%s?%s={search_term_string}" $searchURL $searchParam)
|
||||
"query-input" "required name=search_term_string"
|
||||
)
|
||||
) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $graph := slice $website $author -}}
|
||||
|
||||
{{- if not .IsHome -}}
|
||||
{{- $breadcrumbPages := partial "seo/breadcrumb-pages.html" . -}}
|
||||
{{- if gt (len $breadcrumbPages) 1 -}}
|
||||
{{- $items := slice -}}
|
||||
{{- range $index, $item := $breadcrumbPages -}}
|
||||
{{- $items = $items | append (dict
|
||||
"@type" "ListItem"
|
||||
"position" (add $index 1)
|
||||
"name" (default $item.Title $item.LinkTitle)
|
||||
"item" $item.Permalink
|
||||
) -}}
|
||||
{{- end -}}
|
||||
{{- $graph = $graph | append (dict
|
||||
"@type" "BreadcrumbList"
|
||||
"@id" (printf "%s#breadcrumb" .Permalink)
|
||||
"itemListElement" $items
|
||||
) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if .IsPage -}}
|
||||
{{- $image := partial "seo/image.html" . -}}
|
||||
{{- $pageSchema := dict
|
||||
"@type" (index $pageClassification "jsonLdType")
|
||||
"@id" (printf "%s#webpage" .Permalink)
|
||||
"url" .Permalink
|
||||
"name" .Title
|
||||
"inLanguage" $language
|
||||
"isPartOf" (dict "@id" $websiteID)
|
||||
"author" (dict "@id" $authorID)
|
||||
-}}
|
||||
{{- with $description -}}
|
||||
{{- $pageSchema = merge $pageSchema (dict "description" .) -}}
|
||||
{{- end -}}
|
||||
{{- with $image -}}
|
||||
{{- $pageSchema = merge $pageSchema (dict "image" .) -}}
|
||||
{{- end -}}
|
||||
{{- with .Date -}}
|
||||
{{- $pageSchema = merge $pageSchema (dict "datePublished" (.Format "2006-01-02T15:04:05Z07:00")) -}}
|
||||
{{- end -}}
|
||||
{{- with .Lastmod -}}
|
||||
{{- $pageSchema = merge $pageSchema (dict "dateModified" (.Format "2006-01-02T15:04:05Z07:00")) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if eq (index $pageClassification "jsonLdType") "BlogPosting" -}}
|
||||
{{- $pageSchema = merge $pageSchema (dict
|
||||
"headline" .Title
|
||||
"mainEntityOfPage" .Permalink
|
||||
) -}}
|
||||
{{- with .CurrentSection -}}
|
||||
{{- if ne .RelPermalink "/" -}}
|
||||
{{- $pageSchema = merge $pageSchema (dict "articleSection" .Title) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $keywords := slice -}}
|
||||
{{- with .GetTerms "tags" -}}
|
||||
{{- range . -}}
|
||||
{{- $keywords = $keywords | append .LinkTitle -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if gt (len $keywords) 0 -}}
|
||||
{{- $pageSchema = merge $pageSchema (dict "keywords" $keywords) -}}
|
||||
{{- end -}}
|
||||
{{- else if eq (index $pageClassification "jsonLdType") "Review" -}}
|
||||
{{- $itemReviewed := dict
|
||||
"@type" (index $pageClassification "reviewedType")
|
||||
"name" .Title
|
||||
-}}
|
||||
{{- with .Params.wikidata_id -}}
|
||||
{{- $itemReviewed = merge $itemReviewed (dict "sameAs" (printf "https://www.wikidata.org/wiki/%s" .)) -}}
|
||||
{{- end -}}
|
||||
{{- $pageSchema = merge $pageSchema (dict
|
||||
"itemReviewed" $itemReviewed
|
||||
"mainEntityOfPage" .Permalink
|
||||
) -}}
|
||||
{{- else if eq (index $pageClassification "jsonLdType") "Article" -}}
|
||||
{{- $pageSchema = merge $pageSchema (dict
|
||||
"headline" .Title
|
||||
"mainEntityOfPage" .Permalink
|
||||
) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $graph = $graph | append $pageSchema -}}
|
||||
{{- else if not .IsHome -}}
|
||||
{{- $pageSchema := dict
|
||||
"@type" (index $pageClassification "jsonLdType")
|
||||
"@id" (printf "%s#collection" .Permalink)
|
||||
"url" .Permalink
|
||||
"name" .Title
|
||||
"inLanguage" $language
|
||||
"isPartOf" (dict "@id" $websiteID)
|
||||
-}}
|
||||
{{- with $description -}}
|
||||
{{- $pageSchema = merge $pageSchema (dict "description" .) -}}
|
||||
{{- end -}}
|
||||
{{- $graph = $graph | append $pageSchema -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $payload := dict
|
||||
"@context" "https://schema.org"
|
||||
"@graph" $graph
|
||||
-}}
|
||||
<script type="application/ld+json">{{ $payload | jsonify | safeJS }}</script>
|
||||
{{- end -}}
|
||||
@@ -10,16 +10,13 @@
|
||||
{{- $socialImage := partial "head/social-image.html" . -}}
|
||||
{{- $openGraphImage := $socialImage.openGraph -}}
|
||||
{{- $twitterImage := $socialImage.twitter -}}
|
||||
{{- $searchPath := site.Params.search.action | relURL -}}
|
||||
{{- $isSearchPage := eq .RelPermalink $searchPath -}}
|
||||
{{- $noindex := partial "seo/noindex.html" . -}}
|
||||
{{- $pageClassification := partial "seo/page-classification.html" . -}}
|
||||
{{- $robots := "max-image-preview:large" -}}
|
||||
{{- if $isSearchPage -}}
|
||||
{{- if $noindex -}}
|
||||
{{- $robots = "noindex, follow" -}}
|
||||
{{- end -}}
|
||||
{{- $ogType := "website" -}}
|
||||
{{- if and .IsPage (not $isSearchPage) -}}
|
||||
{{- $ogType = "article" -}}
|
||||
{{- end -}}
|
||||
{{- $ogType := index $pageClassification "openGraphType" -}}
|
||||
{{- $localeCode := site.LanguageCode | default site.Language.LanguageCode | default "fr-FR" -}}
|
||||
{{- $locale := replace $localeCode "-" "_" -}}
|
||||
<title>{{ $title }}</title>
|
||||
@@ -60,7 +57,7 @@
|
||||
{{- with $twitterImage.alt }}
|
||||
<meta name="twitter:image:alt" content="{{ . }}">
|
||||
{{- end }}
|
||||
{{- if eq $ogType "article" -}}
|
||||
{{- if and (eq $ogType "article") (index $pageClassification "isArticleLike") -}}
|
||||
{{- with .Date }}
|
||||
<meta property="article:published_time" content="{{ .Format "2006-01-02T15:04:05Z07:00" }}">
|
||||
{{- end }}
|
||||
|
||||
Reference in New Issue
Block a user