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,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>{{ $title }}</title>
{{- with $description }}
<meta name="description" content="{{ . }}">
{{- end }}
<meta name="theme-color" content="{{ site.Params.themeColor | default "#060c14" }}">
<meta name="theme-color" content="{{ $page.Site.Params.themeColor | default "#060c14" }}">
<meta name="robots" content="{{ $robots }}">
<link rel="canonical" href="{{ .Permalink }}">
<link rel="canonical" href="{{ $page.Permalink }}">
<meta property="og:locale" content="{{ $locale }}">
<meta property="og:site_name" content="{{ site.Title }}">
<meta property="og:site_name" content="{{ $page.Site.Title }}">
<meta property="og:type" content="{{ $ogType }}">
<meta property="og:title" content="{{ $socialTitle }}">
<meta property="og:url" content="{{ .Permalink }}">
<meta property="og:url" content="{{ $page.Permalink }}">
{{- with $description }}
<meta property="og:description" content="{{ . }}">
{{- end }}
@@ -57,11 +57,11 @@
{{- with $twitterImage.alt }}
<meta name="twitter:image:alt" content="{{ . }}">
{{- end }}
{{- if and (eq $ogType "article") (index $pageClassification "isArticleLike") -}}
{{- with .Date }}
{{- if and (eq $ogType "article") (index (index $data "pageClassification") "isArticleLike") -}}
{{- with $page.Date }}
<meta property="article:published_time" content="{{ .Format "2006-01-02T15:04:05Z07:00" }}">
{{- end }}
{{- with .Lastmod }}
{{- with $page.Lastmod }}
<meta property="article:modified_time" content="{{ .Format "2006-01-02T15:04:05Z07:00" }}">
{{- end }}
{{- end -}}