Mutualiser les calculs SEO du head
This commit is contained in:
36
layouts/partials/head/data.html
Normal file
36
layouts/partials/head/data.html
Normal file
@@ -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 "-" "_")
|
||||
-}}
|
||||
@@ -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)
|
||||
-}}
|
||||
|
||||
@@ -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 -}}
|
||||
{{- $socialTitle := site.Title -}}
|
||||
{{- if not .IsHome -}}
|
||||
{{- $socialTitle = .Title -}}
|
||||
{{- with index . "Data" -}}
|
||||
{{- $data = . -}}
|
||||
{{- 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 "-" "_" -}}
|
||||
{{- if eq (len $data) 0 -}}
|
||||
{{- $data = partialCached "head/data.html" $page $page.RelPermalink -}}
|
||||
{{- end -}}
|
||||
{{- $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 -}}
|
||||
|
||||
@@ -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 -}}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
{{ 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) }}
|
||||
<link rel="icon" href="{{ "favicon.ico" | absURL }}" type="image/x-icon">
|
||||
<link rel="shortcut icon" href="{{ "favicon.ico" | absURL }}" type="image/x-icon">
|
||||
<link rel="icon" href="{{ "favicon.png" | absURL }}" type="image/png" sizes="256x256">
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
{{ 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) }}
|
||||
<link rel="icon" href="{{ "favicon.ico" | absURL }}" type="image/x-icon" />
|
||||
<link rel="shortcut icon" href="{{ "favicon.ico" | absURL }}" type="image/x-icon" />
|
||||
<link rel="icon" href="{{ "favicon.png" | absURL }}" type="image/png" sizes="256x256" />
|
||||
|
||||
Reference in New Issue
Block a user