Préserver les GIF animés lors des transformations d'images
This commit is contained in:
@@ -76,7 +76,11 @@
|
|||||||
{{- if gt $coverDisplay.Width 1480 -}}
|
{{- if gt $coverDisplay.Width 1480 -}}
|
||||||
{{- $coverWidth = 1480 -}}
|
{{- $coverWidth = 1480 -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- $coverDisplay = $coverImage.Resize (printf "%dx webp q80" $coverWidth) -}}
|
{{- $coverDisplay = partial "media/process-image.html" (dict
|
||||||
|
"image" $coverImage
|
||||||
|
"action" "Resize"
|
||||||
|
"spec" (printf "%dx" $coverWidth)
|
||||||
|
) -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|||||||
@@ -100,7 +100,11 @@
|
|||||||
{{- $title := default (printf "Image complémentaire : %s" $imageName) (index $data "title") -}}
|
{{- $title := default (printf "Image complémentaire : %s" $imageName) (index $data "title") -}}
|
||||||
{{- $thumbnail := . -}}
|
{{- $thumbnail := . -}}
|
||||||
{{- if and (ne .MediaType.SubType "svg") (gt .Width 360) -}}
|
{{- if and (ne .MediaType.SubType "svg") (gt .Width 360) -}}
|
||||||
{{- $thumbnail = .Resize "360x webp q80" -}}
|
{{- $thumbnail = partial "media/process-image.html" (dict
|
||||||
|
"image" .
|
||||||
|
"action" "Resize"
|
||||||
|
"spec" "360x"
|
||||||
|
) -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ .RelPermalink }}" title="{{ $title }}">
|
<a href="{{ .RelPermalink }}" title="{{ $title }}">
|
||||||
|
|||||||
@@ -41,8 +41,6 @@
|
|||||||
{{- $thumbnailTransform = "900x506" -}}
|
{{- $thumbnailTransform = "900x506" -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- $thumbnailOptions := printf "%s webp q80" $thumbnailTransform -}}
|
|
||||||
|
|
||||||
{{- $coverPath := $page.Params.cover -}}
|
{{- $coverPath := $page.Params.cover -}}
|
||||||
{{- $image := false -}}
|
{{- $image := false -}}
|
||||||
{{- if $coverPath -}}
|
{{- if $coverPath -}}
|
||||||
@@ -111,7 +109,11 @@
|
|||||||
<a href="{{ $page.RelPermalink }}">
|
<a href="{{ $page.RelPermalink }}">
|
||||||
<figure>
|
<figure>
|
||||||
{{- with $image -}}
|
{{- with $image -}}
|
||||||
{{- $resized := .Fill $thumbnailOptions -}}
|
{{- $resized := partial "media/process-image.html" (dict
|
||||||
|
"image" .
|
||||||
|
"action" "Fill"
|
||||||
|
"spec" $thumbnailTransform
|
||||||
|
) -}}
|
||||||
<img src="{{ $resized.RelPermalink }}" alt="Image de couverture pour {{ $page.Title }}" loading="lazy">
|
<img src="{{ $resized.RelPermalink }}" alt="Image de couverture pour {{ $page.Title }}" loading="lazy">
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
</figure>
|
</figure>
|
||||||
@@ -127,7 +129,11 @@
|
|||||||
<a href="{{ $page.RelPermalink }}">
|
<a href="{{ $page.RelPermalink }}">
|
||||||
<figure>
|
<figure>
|
||||||
{{- with $image -}}
|
{{- with $image -}}
|
||||||
{{- $resized := .Fill $thumbnailOptions -}}
|
{{- $resized := partial "media/process-image.html" (dict
|
||||||
|
"image" .
|
||||||
|
"action" "Fill"
|
||||||
|
"spec" $thumbnailTransform
|
||||||
|
) -}}
|
||||||
<img src="{{ $resized.RelPermalink }}" alt="Image de couverture pour {{ $page.Title }}" loading="lazy">
|
<img src="{{ $resized.RelPermalink }}" alt="Image de couverture pour {{ $page.Title }}" loading="lazy">
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
</figure>
|
</figure>
|
||||||
|
|||||||
@@ -15,13 +15,21 @@
|
|||||||
{{- if gt $image.Width $maxWidth -}}
|
{{- if gt $image.Width $maxWidth -}}
|
||||||
{{- $targetWidth = $maxWidth -}}
|
{{- $targetWidth = $maxWidth -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- $display = $image.Resize (printf "%dx webp q80" $targetWidth) -}}
|
{{- $display = partial "media/process-image.html" (dict
|
||||||
|
"image" $image
|
||||||
|
"action" "Resize"
|
||||||
|
"spec" (printf "%dx" $targetWidth)
|
||||||
|
) -}}
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
{{- $targetHeight := $image.Height -}}
|
{{- $targetHeight := $image.Height -}}
|
||||||
{{- if gt $image.Height 900 -}}
|
{{- if gt $image.Height 900 -}}
|
||||||
{{- $targetHeight = 900 -}}
|
{{- $targetHeight = 900 -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- $display = $image.Resize (printf "x%d webp q80" $targetHeight) -}}
|
{{- $display = partial "media/process-image.html" (dict
|
||||||
|
"image" $image
|
||||||
|
"action" "Resize"
|
||||||
|
"spec" (printf "x%d" $targetHeight)
|
||||||
|
) -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
|
|||||||
30
themes/2026/layouts/_partials/media/process-image.html
Normal file
30
themes/2026/layouts/_partials/media/process-image.html
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{{/* Préserve les GIF animés en évitant toute transformation Hugo. */}}
|
||||||
|
{{- $image := .image -}}
|
||||||
|
{{- if not $image -}}
|
||||||
|
{{- errorf "media/process-image.html: missing image resource" -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $action := .action -}}
|
||||||
|
{{- if not $action -}}
|
||||||
|
{{- errorf "media/process-image.html: missing image action for %q" $image.Name -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $spec := .spec -}}
|
||||||
|
{{- if not $spec -}}
|
||||||
|
{{- errorf "media/process-image.html: missing image spec for %q" $image.Name -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- $result := $image -}}
|
||||||
|
{{- $subType := lower $image.MediaType.SubType -}}
|
||||||
|
{{- if and (ne $subType "svg") (ne $subType "gif") -}}
|
||||||
|
{{- $options := printf "%s webp q80" $spec -}}
|
||||||
|
{{- if eq $action "Fill" -}}
|
||||||
|
{{- $result = $image.Fill $options -}}
|
||||||
|
{{- else if eq $action "Resize" -}}
|
||||||
|
{{- $result = $image.Resize $options -}}
|
||||||
|
{{- else -}}
|
||||||
|
{{- errorf "media/process-image.html: unsupported image action %q for %q" $action $image.Name -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- return $result -}}
|
||||||
@@ -4,7 +4,11 @@
|
|||||||
{{- $assetPath := "images/oeuvres/l-anankeisme.png" -}}
|
{{- $assetPath := "images/oeuvres/l-anankeisme.png" -}}
|
||||||
{{- $source := resources.Get $assetPath -}}
|
{{- $source := resources.Get $assetPath -}}
|
||||||
{{- if $source -}}
|
{{- if $source -}}
|
||||||
{{- $img := $source.Resize "320x webp q80" -}}
|
{{- $img := partial "media/process-image.html" (dict
|
||||||
|
"image" $source
|
||||||
|
"action" "Resize"
|
||||||
|
"spec" "320x"
|
||||||
|
) -}}
|
||||||
<img src="{{ $img.RelPermalink }}" width="{{ $img.Width }}" height="{{ $img.Height }}" alt="Couverture de L'Anankéisme" loading="lazy">
|
<img src="{{ $img.RelPermalink }}" width="{{ $img.Width }}" height="{{ $img.Height }}" alt="Couverture de L'Anankéisme" loading="lazy">
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
</figure>
|
</figure>
|
||||||
|
|||||||
@@ -4,7 +4,11 @@
|
|||||||
{{- $assetPath := "images/oeuvres/l-humain-cette-espece-primitive.jpeg" -}}
|
{{- $assetPath := "images/oeuvres/l-humain-cette-espece-primitive.jpeg" -}}
|
||||||
{{- $source := resources.Get $assetPath -}}
|
{{- $source := resources.Get $assetPath -}}
|
||||||
{{- if $source -}}
|
{{- if $source -}}
|
||||||
{{- $img := $source.Resize "320x webp q80" -}}
|
{{- $img := partial "media/process-image.html" (dict
|
||||||
|
"image" $source
|
||||||
|
"action" "Resize"
|
||||||
|
"spec" "320x"
|
||||||
|
) -}}
|
||||||
<img src="{{ $img.RelPermalink }}" width="{{ $img.Width }}" height="{{ $img.Height }}" alt="Couverture de L'Humain, cette espèce primitive" loading="lazy">
|
<img src="{{ $img.RelPermalink }}" width="{{ $img.Width }}" height="{{ $img.Height }}" alt="Couverture de L'Humain, cette espèce primitive" loading="lazy">
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
</figure>
|
</figure>
|
||||||
|
|||||||
@@ -6,7 +6,11 @@
|
|||||||
{{- $logo := resources.GetMatch $logoPath -}}
|
{{- $logo := resources.GetMatch $logoPath -}}
|
||||||
<a href="{{ "/" | relURL }}" aria-label="Revenir à l'accueil">
|
<a href="{{ "/" | relURL }}" aria-label="Revenir à l'accueil">
|
||||||
{{- with $logo -}}
|
{{- with $logo -}}
|
||||||
{{- $resized := .Resize "64x webp q80" -}}
|
{{- $resized := partial "media/process-image.html" (dict
|
||||||
|
"image" .
|
||||||
|
"action" "Resize"
|
||||||
|
"spec" "64x"
|
||||||
|
) -}}
|
||||||
<img src="{{ $resized.RelPermalink }}" alt="">
|
<img src="{{ $resized.RelPermalink }}" alt="">
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
<strong>{{ $site.Title }}</strong>
|
<strong>{{ $site.Title }}</strong>
|
||||||
|
|||||||
@@ -36,7 +36,11 @@
|
|||||||
{{- with $image -}}
|
{{- with $image -}}
|
||||||
<a href="{{ $page.RelPermalink }}">
|
<a href="{{ $page.RelPermalink }}">
|
||||||
<figure>
|
<figure>
|
||||||
{{- $resized := .Fill "600x340 webp q80" -}}
|
{{- $resized := partial "media/process-image.html" (dict
|
||||||
|
"image" .
|
||||||
|
"action" "Fill"
|
||||||
|
"spec" "600x340"
|
||||||
|
) -}}
|
||||||
<img src="{{ $resized.RelPermalink }}" alt="Image de couverture pour {{ $page.Title }}" loading="lazy">
|
<img src="{{ $resized.RelPermalink }}" alt="Image de couverture pour {{ $page.Title }}" loading="lazy">
|
||||||
</figure>
|
</figure>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -315,7 +315,11 @@
|
|||||||
<a href="{{ $page.RelPermalink }}">
|
<a href="{{ $page.RelPermalink }}">
|
||||||
<figure>
|
<figure>
|
||||||
{{- with $image -}}
|
{{- with $image -}}
|
||||||
{{- $resized := .Fill "166x91 webp q80" -}}
|
{{- $resized := partial "media/process-image.html" (dict
|
||||||
|
"image" .
|
||||||
|
"action" "Fill"
|
||||||
|
"spec" "166x91"
|
||||||
|
) -}}
|
||||||
<img src="{{ $resized.RelPermalink }}" alt="Capture du lien {{ $page.Title }}" loading="lazy">
|
<img src="{{ $resized.RelPermalink }}" alt="Capture du lien {{ $page.Title }}" loading="lazy">
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
</figure>
|
</figure>
|
||||||
@@ -401,7 +405,11 @@
|
|||||||
<a href="{{ $item.RelPermalink }}" title="{{ $item.Title }}">
|
<a href="{{ $item.RelPermalink }}" title="{{ $item.Title }}">
|
||||||
<figure>
|
<figure>
|
||||||
{{- with $itemImage -}}
|
{{- with $itemImage -}}
|
||||||
{{- $resized := .Resize "x128 webp q80" -}}
|
{{- $resized := partial "media/process-image.html" (dict
|
||||||
|
"image" .
|
||||||
|
"action" "Resize"
|
||||||
|
"spec" "x128"
|
||||||
|
) -}}
|
||||||
<img src="{{ $resized.RelPermalink }}" alt="{{ $item.Title }}" title="{{ $item.Title }}" loading="lazy">
|
<img src="{{ $resized.RelPermalink }}" alt="{{ $item.Title }}" title="{{ $item.Title }}" loading="lazy">
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
</figure>
|
</figure>
|
||||||
|
|||||||
Reference in New Issue
Block a user