diff --git a/layouts/partials/head/data.html b/layouts/partials/head/data.html new file mode 100644 index 00000000..e5ab585d --- /dev/null +++ b/layouts/partials/head/data.html @@ -0,0 +1,36 @@ +{{- $page := . -}} +{{- $title := $page.Site.Title -}} +{{- if not $page.IsHome -}} + {{- $title = printf "%s | %s" $page.Title $page.Site.Title -}} +{{- end -}} + +{{- $socialTitle := $page.Site.Title -}} +{{- if not $page.IsHome -}} + {{- $socialTitle = $page.Title -}} +{{- end -}} + +{{- $description := partial "head/description.html" $page -}} +{{- $socialImage := partial "head/social-image.html" $page -}} +{{- $noindex := partial "seo/noindex.html" $page -}} +{{- $pageClassification := partial "seo/page-classification.html" $page -}} +{{- $robots := "max-image-preview:large" -}} +{{- if $noindex -}} + {{- $robots = "noindex, follow" -}} +{{- end -}} + +{{- $localeCode := $page.Site.LanguageCode | default $page.Site.Language.LanguageCode | default "fr-FR" -}} + +{{- return dict + "title" $title + "socialTitle" $socialTitle + "description" $description + "socialImage" $socialImage + "openGraphImage" ($socialImage.openGraph | default dict) + "twitterImage" ($socialImage.twitter | default dict) + "noindex" $noindex + "pageClassification" $pageClassification + "robots" $robots + "ogType" (index $pageClassification "openGraphType") + "localeCode" $localeCode + "locale" (replace $localeCode "-" "_") +-}} diff --git a/layouts/partials/head/json-ld.html b/layouts/partials/head/json-ld.html index 30e6fd16..6c067323 100644 --- a/layouts/partials/head/json-ld.html +++ b/layouts/partials/head/json-ld.html @@ -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) -}} diff --git a/layouts/partials/head/metadata.html b/layouts/partials/head/metadata.html index edcdcc5d..c50d633d 100644 --- a/layouts/partials/head/metadata.html +++ b/layouts/partials/head/metadata.html @@ -1,36 +1,36 @@ -{{- $title := site.Title -}} -{{- if not .IsHome -}} - {{- $title = printf "%s | %s" .Title site.Title -}} +{{- $page := . -}} +{{- $data := dict -}} +{{- if reflect.IsMap . -}} + {{- with index . "Page" -}} + {{- $page = . -}} + {{- end -}} + {{- with index . "Data" -}} + {{- $data = . -}} + {{- end -}} {{- end -}} -{{- $socialTitle := site.Title -}} -{{- if not .IsHome -}} - {{- $socialTitle = .Title -}} +{{- if eq (len $data) 0 -}} + {{- $data = partialCached "head/data.html" $page $page.RelPermalink -}} {{- end -}} -{{- $description := partial "head/description.html" . -}} -{{- $socialImage := partial "head/social-image.html" . -}} -{{- $openGraphImage := $socialImage.openGraph -}} -{{- $twitterImage := $socialImage.twitter -}} -{{- $noindex := partial "seo/noindex.html" . -}} -{{- $pageClassification := partial "seo/page-classification.html" . -}} -{{- $robots := "max-image-preview:large" -}} -{{- if $noindex -}} - {{- $robots = "noindex, follow" -}} -{{- end -}} -{{- $ogType := index $pageClassification "openGraphType" -}} -{{- $localeCode := site.LanguageCode | default site.Language.LanguageCode | default "fr-FR" -}} -{{- $locale := replace $localeCode "-" "_" -}} +{{- $title := index $data "title" -}} +{{- $socialTitle := index $data "socialTitle" -}} +{{- $description := index $data "description" -}} +{{- $openGraphImage := index $data "openGraphImage" -}} +{{- $twitterImage := index $data "twitterImage" -}} +{{- $robots := index $data "robots" -}} +{{- $ogType := index $data "ogType" -}} +{{- $locale := index $data "locale" -}} {{ $title }} {{- with $description }} {{- end }} - + - + - + - + {{- with $description }} {{- end }} @@ -57,11 +57,11 @@ {{- with $twitterImage.alt }} {{- end }} -{{- if and (eq $ogType "article") (index $pageClassification "isArticleLike") -}} - {{- with .Date }} +{{- if and (eq $ogType "article") (index (index $data "pageClassification") "isArticleLike") -}} + {{- with $page.Date }} {{- end }} - {{- with .Lastmod }} + {{- with $page.Lastmod }} {{- end }} {{- end -}} diff --git a/layouts/partials/seo/image.html b/layouts/partials/seo/image.html index 79430f24..96700d7f 100644 --- a/layouts/partials/seo/image.html +++ b/layouts/partials/seo/image.html @@ -1,4 +1,17 @@ -{{- $socialImage := partial "head/social-image.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 -}} +{{- $socialImage := index $data "socialImage" -}} {{- $openGraphImage := $socialImage.openGraph -}} {{- $image := dict -}} {{- with $openGraphImage.url -}} diff --git a/themes/2026/layouts/_partials/head.html b/themes/2026/layouts/_partials/head.html index c8358619..badcf44a 100644 --- a/themes/2026/layouts/_partials/head.html +++ b/themes/2026/layouts/_partials/head.html @@ -1,7 +1,8 @@ -{{ partial "head/metadata.html" . }} -{{ partial "head/json-ld.html" . }} +{{- $headData := partialCached "head/data.html" . .RelPermalink -}} +{{ partial "head/metadata.html" (dict "Page" . "Data" $headData) }} +{{ partial "head/json-ld.html" (dict "Page" . "Data" $headData) }} diff --git a/themes/42/layouts/_partials/head.html b/themes/42/layouts/_partials/head.html index 14405d50..f0da0f4d 100644 --- a/themes/42/layouts/_partials/head.html +++ b/themes/42/layouts/_partials/head.html @@ -1,7 +1,8 @@ -{{ partial "head/metadata.html" . }} -{{ partial "head/json-ld.html" . }} +{{- $headData := partialCached "head/data.html" . .RelPermalink -}} +{{ partial "head/metadata.html" (dict "Page" . "Data" $headData) }} +{{ partial "head/json-ld.html" (dict "Page" . "Data" $headData) }}