diff --git a/config/_default/params.yaml b/config/_default/params.yaml index 17c824d..8c3c663 100644 --- a/config/_default/params.yaml +++ b/config/_default/params.yaml @@ -157,5 +157,17 @@ imageProcessing: - webp cover: enabled: true + small: + width: 800 + threshold: 1000 # Only process images above this width + big: + width: 1600 + threshold: 2000 content: enabled: true + small: + width: 480 + threshold: 600 + big: + width: 1024 + threshold: 1200 diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index cdabeb5..642e095 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -3,7 +3,7 @@ {{- $alt := .PlainText | safeHTML -}} {{- $Width := 0 -}} {{- $Height := 0 -}} -{{- $Srcset := "" -}} +{{- $Srcset := slice -}} {{- $imageProcessing := .Page.Site.Params.imageProcessing.content.enabled -}} {{- $allowedTypes := .Page.Site.Params.ImageProcessing.AllowedTypes -}} {{- $resizableTypes := .Page.Site.Params.ImageProcessing.ResizableTypes -}} @@ -22,9 +22,16 @@ {{- $galleryImage = true -}} {{- if $imageProcessing -}} - {{- $small := $image.Resize `480x` -}} - {{- $big := $image.Resize `1024x` -}} - {{- $Srcset = printf `%s 480w, %s 1024w` $small.RelPermalink $big.RelPermalink -}} + {{- $keys := slice "small" "big" -}} + {{- range $keys -}} + {{- with (index $.Page.Site.Params.ImageProcessing.Content .) -}} + {{- if gt $Width .Threshold -}} + {{- $resized := $image.Resize (printf "%dx" .Width) -}} + {{- $Srcset = $Srcset | append (printf `%s %dw` $resized.RelPermalink .Width) -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- $Srcset = $Srcset | append (printf `%s %dw` $Permalink $Width) -}} {{- end -}} {{- end -}} {{- end -}} @@ -32,7 +39,7 @@