Optimisation des images
This commit is contained in:
28
themes/2026/layouts/_partials/media/display-img.html
Normal file
28
themes/2026/layouts/_partials/media/display-img.html
Normal 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 }}">
|
||||
Reference in New Issue
Block a user