feat: Resize image only if width are great than maxWidth
This commit is contained in:
parent
e0b3ed9a0f
commit
7dd4dbfd3c
|
@ -1,11 +1,15 @@
|
||||||
|
|
||||||
{{/*
|
{{/*
|
||||||
S'il n'y a pas de / dans l'url d'une image alors on ajoute le path de l'article
|
S'il n'y a pas de / dans l'url d'une image alors on ajoute le path de l'article
|
||||||
*/}}
|
*/}}
|
||||||
{{ $path := cond (in .Destination "/") .Destination (path.Join "/" .Page.File.Dir .Destination) }}
|
{{ $path := cond (in .Destination "/") .Destination (path.Join "/" .Page.File.Dir .Destination) }}
|
||||||
{{ $image := .Page.Resources.GetMatch (printf "*%s*" .Destination) }}
|
{{ $image := .Page.Resources.GetMatch (printf "*%s*" .Destination) }}
|
||||||
{{ with $image }}
|
{{ with $image }}
|
||||||
|
{{ $maxWidth := (default "610" site.Params.ImageWidth) }}
|
||||||
|
{{ if gt $image.Width $maxWidth }}
|
||||||
{{ $resizeParams := delimit (slice (default "610x" site.Params.ImageSize) (default "q100" site.Params.ImageQuality) (default "webp" site.Params.ImageFormat)) " " }}
|
{{ $resizeParams := delimit (slice (default "610x" site.Params.ImageSize) (default "q100" site.Params.ImageQuality) (default "webp" site.Params.ImageFormat)) " " }}
|
||||||
{{ $resized := $image.Resize (string $resizeParams) }}
|
{{ $resized := $image.Resize (string $resizeParams) }}
|
||||||
{{ $path = $resized.RelPermalink }}
|
{{ $path = $resized.RelPermalink }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
{{ end }}
|
||||||
<img src="{{ $path | safeURL }}" alt="{{ .Text }}" {{ with .Title}} title="{{ . }}"{{ end }} loading="lazy" />
|
<img src="{{ $path | safeURL }}" alt="{{ .Text }}" {{ with .Title}} title="{{ . }}"{{ end }} loading="lazy" />
|
||||||
|
|
Loading…
Reference in New Issue