Images sociales
This commit is contained in:
@@ -8,6 +8,8 @@
|
|||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- $description := partial "head/description.html" . -}}
|
{{- $description := partial "head/description.html" . -}}
|
||||||
{{- $socialImage := partial "head/social-image.html" . -}}
|
{{- $socialImage := partial "head/social-image.html" . -}}
|
||||||
|
{{- $openGraphImage := $socialImage.openGraph -}}
|
||||||
|
{{- $twitterImage := $socialImage.twitter -}}
|
||||||
{{- $searchPath := site.Params.search.action | relURL -}}
|
{{- $searchPath := site.Params.search.action | relURL -}}
|
||||||
{{- $isSearchPage := eq .RelPermalink $searchPath -}}
|
{{- $isSearchPage := eq .RelPermalink $searchPath -}}
|
||||||
{{- $robots := "max-image-preview:large" -}}
|
{{- $robots := "max-image-preview:large" -}}
|
||||||
@@ -35,16 +37,16 @@
|
|||||||
{{- with $description }}
|
{{- with $description }}
|
||||||
<meta property="og:description" content="{{ . }}">
|
<meta property="og:description" content="{{ . }}">
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with $socialImage.url }}
|
{{- with $openGraphImage.url }}
|
||||||
<meta property="og:image" content="{{ . }}">
|
<meta property="og:image" content="{{ . }}">
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with $socialImage.width }}
|
{{- with $openGraphImage.width }}
|
||||||
<meta property="og:image:width" content="{{ . }}">
|
<meta property="og:image:width" content="{{ . }}">
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with $socialImage.height }}
|
{{- with $openGraphImage.height }}
|
||||||
<meta property="og:image:height" content="{{ . }}">
|
<meta property="og:image:height" content="{{ . }}">
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with $socialImage.alt }}
|
{{- with $openGraphImage.alt }}
|
||||||
<meta property="og:image:alt" content="{{ . }}">
|
<meta property="og:image:alt" content="{{ . }}">
|
||||||
{{- end }}
|
{{- end }}
|
||||||
<meta name="twitter:card" content="summary">
|
<meta name="twitter:card" content="summary">
|
||||||
@@ -52,10 +54,10 @@
|
|||||||
{{- with $description }}
|
{{- with $description }}
|
||||||
<meta name="twitter:description" content="{{ . }}">
|
<meta name="twitter:description" content="{{ . }}">
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with $socialImage.url }}
|
{{- with $twitterImage.url }}
|
||||||
<meta name="twitter:image" content="{{ . }}">
|
<meta name="twitter:image" content="{{ . }}">
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- with $socialImage.alt }}
|
{{- with $twitterImage.alt }}
|
||||||
<meta name="twitter:image:alt" content="{{ . }}">
|
<meta name="twitter:image:alt" content="{{ . }}">
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if eq $ogType "article" -}}
|
{{- if eq $ogType "article" -}}
|
||||||
|
|||||||
54
layouts/partials/head/social-image-variant.html
Normal file
54
layouts/partials/head/social-image-variant.html
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
{{- $image := .image -}}
|
||||||
|
{{- if not $image -}}
|
||||||
|
{{- errorf "head/social-image-variant.html: missing image resource" -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $targetWidth := .width -}}
|
||||||
|
{{- if not $targetWidth -}}
|
||||||
|
{{- errorf "head/social-image-variant.html: missing target width for %q" $image.Name -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $targetHeight := .height -}}
|
||||||
|
{{- if not $targetHeight -}}
|
||||||
|
{{- errorf "head/social-image-variant.html: missing target height for %q" $image.Name -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $anchor := .anchor -}}
|
||||||
|
{{- if not $anchor -}}
|
||||||
|
{{- errorf "head/social-image-variant.html: missing crop anchor for %q" $image.Name -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $subType := lower $image.MediaType.SubType -}}
|
||||||
|
{{- if eq $subType "svg" -}}
|
||||||
|
{{- errorf "head/social-image-variant.html: unsupported svg image %q" $image.Name -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $width := $targetWidth -}}
|
||||||
|
{{- $height := $targetHeight -}}
|
||||||
|
{{- if ge (mul $image.Width $targetHeight) (mul $image.Height $targetWidth) -}}
|
||||||
|
{{- if lt $image.Height $height -}}
|
||||||
|
{{- $height = $image.Height -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- $width = div (mul $height $targetWidth) $targetHeight -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{- if lt $image.Width $width -}}
|
||||||
|
{{- $width = $image.Width -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- $height = div (mul $width $targetHeight) $targetWidth -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $format := "jpg q85" -}}
|
||||||
|
{{- if eq $subType "png" -}}
|
||||||
|
{{- $format = "png" -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $variant := $image.Fill (printf "%dx%d %s %s" $width $height $anchor $format) -}}
|
||||||
|
{{- if .blur -}}
|
||||||
|
{{- $variant = $variant.Filter (images.GaussianBlur 6) -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- return dict
|
||||||
|
"url" $variant.Permalink
|
||||||
|
"width" $variant.Width
|
||||||
|
"height" $variant.Height
|
||||||
|
"alt" (.alt | strings.TrimSpace | truncate 420)
|
||||||
|
-}}
|
||||||
@@ -39,17 +39,33 @@
|
|||||||
{{- $alt = printf "Logo du site %s" site.Title -}}
|
{{- $alt = printf "Logo du site %s" site.Title -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- $data := dict -}}
|
{{- $data := dict -}}
|
||||||
{{- if $image -}}
|
{{- 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
|
{{- $data = dict
|
||||||
"url" $image.Permalink
|
"openGraph" (partial "head/social-image-variant.html" (dict
|
||||||
"alt" ($alt | strings.TrimSpace | truncate 420)
|
"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
|
||||||
|
))
|
||||||
-}}
|
-}}
|
||||||
{{- with $image.Width -}}
|
|
||||||
{{- $data = merge $data (dict "width" .) -}}
|
|
||||||
{{- end -}}
|
|
||||||
{{- with $image.Height -}}
|
|
||||||
{{- $data = merge $data (dict "height" .) -}}
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- return $data -}}
|
{{- return $data -}}
|
||||||
|
|||||||
Reference in New Issue
Block a user