Ajoute des métadonnées de partage et d'indexation
This commit is contained in:
55
layouts/partials/head/social-image.html
Normal file
55
layouts/partials/head/social-image.html
Normal file
@@ -0,0 +1,55 @@
|
||||
{{- $image := false -}}
|
||||
{{- $isCoverImage := false -}}
|
||||
{{- $alt := "" -}}
|
||||
{{- with .Params.cover -}}
|
||||
{{- $cover := $.Resources.GetMatch . -}}
|
||||
{{- if and $cover (ne $cover.MediaType.SubType "svg") -}}
|
||||
{{- $image = $cover -}}
|
||||
{{- $isCoverImage = true -}}
|
||||
{{- $coverName := path.Base . | replaceRE "\\.[^.]+$" "" -}}
|
||||
{{- $coverDataFile := $.Resources.Get (printf "data/images/%s.yaml" $coverName) -}}
|
||||
{{- if not $coverDataFile -}}
|
||||
{{- $coverDataFile = $.Resources.Get (printf "data/%s.yaml" $coverName) -}}
|
||||
{{- end -}}
|
||||
{{- $coverData := dict -}}
|
||||
{{- if $coverDataFile -}}
|
||||
{{- $coverData = $coverDataFile.Content | transform.Unmarshal -}}
|
||||
{{- end -}}
|
||||
{{- $alt = index $coverData "description" | default "" -}}
|
||||
{{- if not $alt -}}
|
||||
{{- $alt = index $coverData "title" | default "" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if not $image -}}
|
||||
{{- $logoPath := site.Params.logo | default "logo-large.png" -}}
|
||||
{{- $logo := resources.GetMatch $logoPath -}}
|
||||
{{- if and $logo (ne $logo.MediaType.SubType "svg") -}}
|
||||
{{- $image = $logo -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- if not $alt -}}
|
||||
{{- if and $image $isCoverImage -}}
|
||||
{{- if and .IsPage (not .IsHome) -}}
|
||||
{{- $alt = printf "Image de partage pour %s" .Title -}}
|
||||
{{- else -}}
|
||||
{{- $alt = printf "Logo du site %s" site.Title -}}
|
||||
{{- end -}}
|
||||
{{- else if $image -}}
|
||||
{{- $alt = printf "Logo du site %s" site.Title -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- $data := dict -}}
|
||||
{{- if $image -}}
|
||||
{{- $data = dict
|
||||
"url" $image.Permalink
|
||||
"alt" ($alt | strings.TrimSpace | truncate 420)
|
||||
-}}
|
||||
{{- with $image.Width -}}
|
||||
{{- $data = merge $data (dict "width" .) -}}
|
||||
{{- end -}}
|
||||
{{- with $image.Height -}}
|
||||
{{- $data = merge $data (dict "height" .) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- return $data -}}
|
||||
Reference in New Issue
Block a user