From cc5e75e4691a6b0cbb55aff1de786e7ca1b699aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20K=C3=A1n=C4=9B?= Date: Mon, 20 Apr 2020 13:35:43 +0200 Subject: [PATCH 1/2] Fix blogPhoto shortcode w unit inside srcset means width in original photo pixels, not height --- themes/patek/layouts/shortcodes/blogPhoto.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/patek/layouts/shortcodes/blogPhoto.html b/themes/patek/layouts/shortcodes/blogPhoto.html index 3c1396e..823581c 100644 --- a/themes/patek/layouts/shortcodes/blogPhoto.html +++ b/themes/patek/layouts/shortcodes/blogPhoto.html @@ -26,4 +26,4 @@ or {{- $resizedHD := $img.Fit "1280x720 q50" -}} {{- $resizedSD := $img.Fit "640x360 q50" -}} -{{ $alt }} +{{ $alt }} From 315ec5b77bed7299c3cec1d8f451bfc430fd4c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20K=C3=A1n=C4=9B?= Date: Mon, 20 Apr 2020 13:54:08 +0200 Subject: [PATCH 2/2] Generalize blogPhoto shortcode Generate the resized images from simple config array + generate only those, that are actualy smaller then the original. --- themes/patek/layouts/shortcodes/blogPhoto.html | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/themes/patek/layouts/shortcodes/blogPhoto.html b/themes/patek/layouts/shortcodes/blogPhoto.html index 823581c..23ba285 100644 --- a/themes/patek/layouts/shortcodes/blogPhoto.html +++ b/themes/patek/layouts/shortcodes/blogPhoto.html @@ -20,10 +20,17 @@ or {{- if (eq $imageName nil) }}{{ errorf "Missing image name in %s" .Position }}{{ end -}} {{- if (eq $alt nil) }}{{ errorf "Missing alt for image %s in %s" $imageName .Position }}{{ end -}} -{{- $img := .Page.Resources.GetMatch (printf "%s" $imageName) | default nil -}} +{{- $img := .Page.Resources.GetMatch $imageName | default nil -}} {{- if (eq $img nil) }}{{ errorf "Image %s not found in %s" $imageName .Position }}{{ end -}} -{{- $resizedFullHD := $img.Fit "1920x1080 q50" -}} -{{- $resizedHD := $img.Fit "1280x720 q50" -}} -{{- $resizedSD := $img.Fit "640x360 q50" -}} +{{- $sizes := slice (slice 640 360 50) (slice 1280 720 50) (slice 1920 1080 50) -}} +{{- $srcset := slice -}} +{{- $largest := index $sizes 0 -}} +{{- 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)) -}} + {{- $srcset = $srcset | append (printf "%s %dw" $resized.RelPermalink (index . 0)) -}} + {{- $largest = $resized -}} + {{- end -}} +{{- end -}} -{{ $alt }} +{{ $alt }}