Browse Source

allow for varied image filetypes in shortcode and partial

master
Alexander Avery 4 days ago
parent
commit
57ee13a0bb
  1. 7
      layouts/partials/image.html
  2. 3
      layouts/shortcodes/image.html

7
layouts/partials/image.html

@ -4,12 +4,15 @@ Renders an image with the given class, alt, and sizes.
@context {image} the image resource.
@context {sizes} each size to include in the srcset.
@context {classes} classes for the image.
@context {ext} extension of output image.
*/}}
{{- $alt := .alt }}
{{- $img := .image }}
{{- $sizes := .sizes }}
{{- $classes := .classes }}
{{- $ext := .ext }}
{{- $srcsetParts := slice }}
{{- $sizesParts := slice }}
@ -18,7 +21,7 @@ Renders an image with the given class, alt, and sizes.
{{- if .image }}
{{/* Loop through widths to resize images and build attributes */}}
{{- range $index, $width := $sizes }}
{{- $resizeSpec := printf "%dx webp q90" $width }}
{{- $resizeSpec := printf "%dx %s q90" $width $ext }}
{{- $resized := ($img.Resize $resizeSpec) }}
{{- $srcsetParts = $srcsetParts | append (printf "%s %dw" $resized.RelPermalink $width) }}
@ -33,7 +36,7 @@ Renders an image with the given class, alt, and sizes.
{{- end }}
{{- $smallestWidth := index $sizes 0 }}
{{- $smallestResizeSpec := printf "%dx webp q90" $smallestWidth }}
{{- $smallestResizeSpec := printf "%dx %s q90" $smallestWidth $ext }}
{{- $smallest := ($img.Resize $smallestResizeSpec) }}
{{- $src := $smallest.RelPermalink }}
<img class="{{ delimit $classes " " }}"

3
layouts/shortcodes/image.html

@ -4,4 +4,5 @@
"image" $image
"alt" (.Get "alt")
"sizes" (slice 320 480 600)
"classes" (slice "fill-wh")) }}
"classes" (slice "fill-wh"))
"ext" (.Get "ext" | default "webp" ) }}

Loading…
Cancel
Save