diff --git a/themes/patek/layouts/shortcodes/blogPhoto.html b/themes/patek/layouts/shortcodes/blogPhoto.html index 58f82ca..f57d60e 100644 --- a/themes/patek/layouts/shortcodes/blogPhoto.html +++ b/themes/patek/layouts/shortcodes/blogPhoto.html @@ -11,6 +11,7 @@ where possible named params are: * src - path to the image in page bundle * alt - textual description of the image, the alt attribute * caption (optional) - the caption displayed under the image, defaults to `alt`. Set to false to disable caption rendering +* format (optional) - the format of the images, defaults to `jpg`, available formats here: https://gohugo.io/content-management/image-processing/#target-format */ -}} {{- $imageName := false -}} @@ -31,16 +32,29 @@ where possible named params are: {{- $sizes := slice (slice 640 360 50) (slice 1280 720 50) (slice 1920 1080 50) -}} {{- $srcset := slice -}} {{- $largest := false -}} + +{{- $format := (.Get "format") -}} {{- 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)) -}} + {{- $resized := false }} + {{- if or (eq $format false) (eq $format "jpg") }} + {{- $resized = $img.Fit (printf "%dx%d q%d" (index . 0) (index . 1) (index . 2)) -}} + {{- else -}} + {{- $resized = $img.Fit (printf "%dx%d %s" (index . 0) (index . 1) $format) -}} + {{- end -}} + {{- $srcset = $srcset | append (printf "%s %dw" $resized.RelPermalink (index . 0)) -}} {{- $largest = $resized -}} {{- end -}} {{- end -}} {{- if (lt (len $srcset) (len $sizes)) -}} - {{- $compressed := $img.Fit (printf "%dx%d q90" $img.Width $img.Height) -}} + {{- $compressed := false }} + {{- if or (eq $format false) (eq $format "jpg") }} + {{- $compressed = $img.Fit (printf "%dx%d q90" $img.Width $img.Height) -}} + {{- else -}} + {{- $compressed = $img.Fit (printf "%dx%d %s" $img.Width $img.Height $format) -}} + {{- end -}} {{- $srcset = $srcset | append (printf "%s %dw" $compressed.RelPermalink $compressed.Width) -}} {{- $largest = $compressed -}} {{- end -}}