1

Mutualiser les calculs SEO du head

This commit is contained in:
2026-04-02 22:38:13 +02:00
parent ba73a3278a
commit 10070c3e4f
6 changed files with 130 additions and 66 deletions

View File

@@ -1,26 +1,39 @@
{{- $noindex := partial "seo/noindex.html" . -}}
{{- $page := . -}}
{{- $data := dict -}}
{{- if reflect.IsMap . -}}
{{- with index . "Page" -}}
{{- $page = . -}}
{{- end -}}
{{- with index . "Data" -}}
{{- $data = . -}}
{{- end -}}
{{- end -}}
{{- if eq (len $data) 0 -}}
{{- $data = partialCached "head/data.html" $page $page.RelPermalink -}}
{{- end -}}
{{- $noindex := index $data "noindex" -}}
{{- 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" . -}}
{{- $language := index $data "localeCode" -}}
{{- $description := index $data "description" -}}
{{- $pageClassification := index $data "pageClassification" -}}
{{- $websiteID := printf "%s#website" $page.Site.Home.Permalink -}}
{{- $author := partial "seo/person.html" $page -}}
{{- $authorID := index $author "@id" -}}
{{- $website := dict
"@type" "WebSite"
"@id" $websiteID
"url" site.Home.Permalink
"name" site.Title
"url" $page.Site.Home.Permalink
"name" $page.Site.Title
"inLanguage" $language
"author" (dict "@id" $authorID)
-}}
{{- with site.Params.description -}}
{{- with $page.Site.Params.description -}}
{{- $website = merge $website (dict "description" .) -}}
{{- end -}}
{{- with site.Params.search -}}
{{- with $page.Site.Params.search -}}
{{- with .action -}}
{{- $searchURL := . | absURL -}}
{{- $searchParam := $.Site.Params.search.param | default "q" -}}
{{- $searchParam := $page.Site.Params.search.param | default "q" -}}
{{- $website = merge $website (dict
"potentialAction" (dict
"@type" "SearchAction"
@@ -33,8 +46,8 @@
{{- $graph := slice $website $author -}}
{{- if not .IsHome -}}
{{- $breadcrumbPages := partial "seo/breadcrumb-pages.html" . -}}
{{- if not $page.IsHome -}}
{{- $breadcrumbPages := partial "seo/breadcrumb-pages.html" $page -}}
{{- if gt (len $breadcrumbPages) 1 -}}
{{- $items := slice -}}
{{- range $index, $item := $breadcrumbPages -}}
@@ -47,19 +60,19 @@
{{- end -}}
{{- $graph = $graph | append (dict
"@type" "BreadcrumbList"
"@id" (printf "%s#breadcrumb" .Permalink)
"@id" (printf "%s#breadcrumb" $page.Permalink)
"itemListElement" $items
) -}}
{{- end -}}
{{- end -}}
{{- if .IsPage -}}
{{- $image := partial "seo/image.html" . -}}
{{- if $page.IsPage -}}
{{- $image := partial "seo/image.html" (dict "Page" $page "Data" $data) -}}
{{- $pageSchema := dict
"@type" (index $pageClassification "jsonLdType")
"@id" (printf "%s#webpage" .Permalink)
"url" .Permalink
"name" .Title
"@id" (printf "%s#webpage" $page.Permalink)
"url" $page.Permalink
"name" $page.Title
"inLanguage" $language
"isPartOf" (dict "@id" $websiteID)
"author" (dict "@id" $authorID)
@@ -70,31 +83,31 @@
{{- with $image -}}
{{- $pageSchema = merge $pageSchema (dict "image" .) -}}
{{- end -}}
{{- with .Date -}}
{{- with $page.Date -}}
{{- $pageSchema = merge $pageSchema (dict "datePublished" (.Format "2006-01-02T15:04:05Z07:00")) -}}
{{- end -}}
{{- with .Lastmod -}}
{{- with $page.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
"headline" $page.Title
"mainEntityOfPage" $page.Permalink
) -}}
{{- with .CurrentSection -}}
{{- with $page.CurrentSection -}}
{{- if ne .RelPermalink "/" -}}
{{- $pageSchema = merge $pageSchema (dict "articleSection" .Title) -}}
{{- end -}}
{{- end -}}
{{- $keywords := slice -}}
{{- $taxonomyNames := slice -}}
{{- range $taxonomy, $_ := .Site.Taxonomies -}}
{{- range $taxonomy, $_ := $page.Site.Taxonomies -}}
{{- $taxonomyNames = $taxonomyNames | append $taxonomy -}}
{{- end -}}
{{- range sort $taxonomyNames -}}
{{- $taxonomy := . -}}
{{- with $.GetTerms $taxonomy -}}
{{- with $page.GetTerms $taxonomy -}}
{{- range sort . "LinkTitle" -}}
{{- $keyword := strings.TrimSpace (printf "%v" (default .Title .LinkTitle)) -}}
{{- if ne $keyword "" -}}
@@ -110,29 +123,29 @@
{{- else if eq (index $pageClassification "jsonLdType") "Review" -}}
{{- $itemReviewed := dict
"@type" (index $pageClassification "reviewedType")
"name" .Title
"name" $page.Title
-}}
{{- with .Params.wikidata_id -}}
{{- with $page.Params.wikidata_id -}}
{{- $itemReviewed = merge $itemReviewed (dict "sameAs" (printf "https://www.wikidata.org/wiki/%s" .)) -}}
{{- end -}}
{{- $pageSchema = merge $pageSchema (dict
"itemReviewed" $itemReviewed
"mainEntityOfPage" .Permalink
"mainEntityOfPage" $page.Permalink
) -}}
{{- else if eq (index $pageClassification "jsonLdType") "Article" -}}
{{- $pageSchema = merge $pageSchema (dict
"headline" .Title
"mainEntityOfPage" .Permalink
"headline" $page.Title
"mainEntityOfPage" $page.Permalink
) -}}
{{- end -}}
{{- $graph = $graph | append $pageSchema -}}
{{- else if not .IsHome -}}
{{- else if not $page.IsHome -}}
{{- $pageSchema := dict
"@type" (index $pageClassification "jsonLdType")
"@id" (printf "%s#collection" .Permalink)
"url" .Permalink
"name" .Title
"@id" (printf "%s#collection" $page.Permalink)
"url" $page.Permalink
"name" $page.Title
"inLanguage" $language
"isPartOf" (dict "@id" $websiteID)
-}}