|
|
@ -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 " " }}" |
|
|
|