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

@@ -71,8 +71,12 @@
{{- $coverImage = $page.Resources.GetMatch $coverPath -}}
{{- if $coverImage -}}
{{- $coverDisplay = $coverImage -}}
{{- if and (ne $coverDisplay.MediaType.SubType "svg") (gt $coverDisplay.Width 1480) -}}
{{- $coverDisplay = $coverImage.Resize "1480x" -}}
{{- if ne $coverDisplay.MediaType.SubType "svg" -}}
{{- $coverWidth := $coverDisplay.Width -}}
{{- if gt $coverDisplay.Width 1480 -}}
{{- $coverWidth = 1480 -}}
{{- end -}}
{{- $coverDisplay = $coverImage.Resize (printf "%dx webp q80" $coverWidth) -}}
{{- end -}}
{{- end -}}
{{- end -}}

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">

View File

@@ -8,11 +8,16 @@
{{- $extension := path.Ext $remoteURL -}}
{{- $cleanFilename := printf "%s%s" $hash $extension | replace "?raw=true" "" -}}
{{- $localImage := $remoteImage | resources.Copy (printf "remote-images/%s" $cleanFilename) -}}
{{- $resizedImage := $localImage.Resize "1024x" -}}
{{- $hasMeta := or $title (or $description $attribution) -}}
<figure class="figure-media{{ if $hasMeta }} figure-media-with-meta{{ else }} figure-media-without-meta{{ end }}">
<a href="{{ $localImage.RelPermalink }}" title="Cliquez pour agrandir l'image">
<img src="{{ $resizedImage.RelPermalink }}" alt="{{ $title }}" title="{{ $title }}">
{{- partial "media/display-img.html" (dict
"image" $localImage
"showMeta" $hasMeta
"forceCentered" false
"alt" $title
"title" $title
) -}}
</a>
{{- if $hasMeta -}}
<figcaption class="figure-media-meta cover-meta">