93 lines
3.0 KiB
HTML
93 lines
3.0 KiB
HTML
{{- $image := false -}}
|
|
{{- $isCoverImage := false -}}
|
|
{{- $alt := "" -}}
|
|
{{- with .Params.cover -}}
|
|
{{- $cover := false -}}
|
|
{{- $coverPath := (urls.Parse .).Path -}}
|
|
{{- if ne $coverPath "" -}}
|
|
{{- $coverPathLower := lower $coverPath -}}
|
|
{{- if or (strings.HasSuffix $coverPathLower ".yaml") (strings.HasSuffix $coverPathLower ".yml") -}}
|
|
{{- $coverDataFile := $.Resources.Get $coverPath -}}
|
|
{{- if $coverDataFile -}}
|
|
{{- with $coverDataFile.Content | transform.Unmarshal -}}
|
|
{{- with index . "file" -}}
|
|
{{- $coverFilePath := strings.TrimSpace (printf "%v" .) -}}
|
|
{{- if ne $coverFilePath "" -}}
|
|
{{- $cover = $.Resources.Get $coverFilePath -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- else -}}
|
|
{{- $cover = $.Resources.Get $coverPath -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- 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 -}}
|
|
{{- with $coverDataFile.Content | transform.Unmarshal -}}
|
|
{{- $coverData = . -}}
|
|
{{- end -}}
|
|
{{- 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 -}}
|
|
{{- $isInterestingLink := and $isCoverImage (strings.HasPrefix .RelPermalink "/interets/liens-interessants/") -}}
|
|
{{- $shouldBlur := $isInterestingLink -}}
|
|
{{- $cropAnchor := "Center" -}}
|
|
{{- if $isInterestingLink -}}
|
|
{{- $cropAnchor = "Top" -}}
|
|
{{- end -}}
|
|
{{- $alt = $alt | strings.TrimSpace | truncate 420 -}}
|
|
{{- $data = dict
|
|
"openGraph" (partial "head/social-image-variant.html" (dict
|
|
"image" $image
|
|
"width" 1200
|
|
"height" 630
|
|
"anchor" $cropAnchor
|
|
"alt" $alt
|
|
"blur" $shouldBlur
|
|
))
|
|
"twitter" (partial "head/social-image-variant.html" (dict
|
|
"image" $image
|
|
"width" 1200
|
|
"height" 1200
|
|
"anchor" $cropAnchor
|
|
"alt" $alt
|
|
"blur" $shouldBlur
|
|
))
|
|
-}}
|
|
{{- end -}}
|
|
{{- return $data -}}
|