From 891110771e5501dda6dfb6930a8d4817bc7bc61b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20K=C3=A1n=C4=9B?= Date: Mon, 20 Apr 2020 23:06:27 +0200 Subject: [PATCH] Include the compressed original image in src/srcset, if it happens to be smaller than the largest size we resize to. --- themes/patek/layouts/shortcodes/blogPhoto.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/themes/patek/layouts/shortcodes/blogPhoto.html b/themes/patek/layouts/shortcodes/blogPhoto.html index 23ba285..8b5b361 100644 --- a/themes/patek/layouts/shortcodes/blogPhoto.html +++ b/themes/patek/layouts/shortcodes/blogPhoto.html @@ -24,7 +24,7 @@ or {{- if (eq $img nil) }}{{ errorf "Image %s not found in %s" $imageName .Position }}{{ end -}} {{- $sizes := slice (slice 640 360 50) (slice 1280 720 50) (slice 1920 1080 50) -}} {{- $srcset := slice -}} -{{- $largest := index $sizes 0 -}} +{{- $largest := false -}} {{- range $sizes -}} {{- if (or (gt $img.Width (index . 0)) (gt $img.Height (index . 1))) -}} {{- $resized := $img.Fit (printf "%dx%d q%d" (index . 0) (index . 1) (index . 2)) -}} @@ -33,4 +33,10 @@ or {{- end -}} {{- end -}} +{{- if (lt (len $srcset) (len $sizes)) -}} + {{- $compressed := $img.Fit (printf "%dx%d q50" $img.Width $img.Height) -}} + {{- $srcset = $srcset | append (printf "%s %dw" $compressed.RelPermalink $compressed.Width) -}} + {{- $largest = $compressed -}} +{{- end -}} + {{ $alt }}