From 7dd4dbfd3cfe0e0214331bbfd6c1b588c4a7c5a7 Mon Sep 17 00:00:00 2001 From: Simon C Date: Thu, 3 Mar 2022 09:31:17 +0100 Subject: [PATCH] feat: Resize image only if width are great than maxWidth --- layouts/_default/_markup/render-image.html | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 7a5a89a..657f8d1 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -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 */}} {{ $path := cond (in .Destination "/") .Destination (path.Join "/" .Page.File.Dir .Destination) }} {{ $image := .Page.Resources.GetMatch (printf "*%s*" .Destination) }} {{ with $image }} - {{ $resizeParams := delimit (slice (default "610x" site.Params.ImageSize) (default "q100" site.Params.ImageQuality) (default "webp" site.Params.ImageFormat)) " " }} - {{ $resized := $image.Resize (string $resizeParams) }} - {{ $path = $resized.RelPermalink }} + {{ $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)) " " }} + {{ $resized := $image.Resize (string $resizeParams) }} + {{ $path = $resized.RelPermalink }} + {{ end }} {{ end }} {{ .Text }}