1

Optimisation des images

This commit is contained in:
2026-03-05 23:53:53 +01:00
parent c28e9ffeaa
commit 1a341d428e
4 changed files with 48 additions and 9 deletions

View File

@@ -0,0 +1,28 @@
{{- $image := .image -}}
{{- $showMeta := .showMeta -}}
{{- $forceCentered := .forceCentered -}}
{{- $alt := .alt -}}
{{- $title := .title -}}
{{- $display := $image -}}
{{- if ne $image.MediaType.SubType "svg" -}}
{{- if gt $image.Width $image.Height -}}
{{- $maxWidth := 1400 -}}
{{- if and $showMeta (not $forceCentered) -}}
{{- $maxWidth = 900 -}}
{{- end -}}
{{- $targetWidth := $image.Width -}}
{{- if gt $image.Width $maxWidth -}}
{{- $targetWidth = $maxWidth -}}
{{- end -}}
{{- $display = $image.Resize (printf "%dx webp q80" $targetWidth) -}}
{{- else -}}
{{- $targetHeight := $image.Height -}}
{{- if gt $image.Height 900 -}}
{{- $targetHeight = 900 -}}
{{- end -}}
{{- $display = $image.Resize (printf "x%d webp q80" $targetHeight) -}}
{{- end -}}
{{- end -}}
<img src="{{ $display.RelPermalink }}" alt="{{ $alt }}" title="{{ $title }}">

View File

@@ -13,10 +13,6 @@
{{- if not $image -}}
{{- return -}}
{{- end -}}
{{- $display := $image -}}
{{- if and (ne $display.MediaType.SubType "svg") (gt $display.Height 810) -}}
{{- $display = $image.Resize "x810" -}}
{{- end -}}
{{- $metaTitle := index $data "title" -}}
{{- $hasMeta := or $metaTitle (or $description (or $data.attribution $data.prompt)) -}}
{{- $attributes := .Attributes | default dict -}}
@@ -56,7 +52,13 @@
{{- end -}}
<figure class="{{ delimit $figureClasses " " }}">
<a href="{{ $image.RelPermalink }}" title="Cliquez pour agrandir l'image">
<img src="{{ $display.RelPermalink }}" alt="{{ $alt }}" title="{{ $title }}">
{{- partial "media/display-img.html" (dict
"image" $image
"showMeta" $showMeta
"forceCentered" $forceCentered
"alt" $alt
"title" $title
) -}}
</a>
{{- if $showMeta -}}
<figcaption class="figure-media-meta cover-meta">