|
13 | 13 | {{- $name := $image.RelPermalink | strings.TrimSuffix (printf ".%s" $image.MediaType.SubType) -}} |
14 | 14 | {{- $extension := $image.MediaType.SubType -}} |
15 | 15 |
|
16 | | -<picture> |
17 | | - {{- $widths := slice -}} |
18 | | - {{- if gt $image.Width 500 -}} |
19 | | - {{- $widths = $widths | append 500 -}} |
20 | | - {{- end -}} |
21 | | - {{- if gt $image.Width 800 -}} |
22 | | - {{- $widths = $widths | append 800 -}} |
23 | | - {{- end -}} |
24 | | - {{- if gt $image.Width 1200 -}} |
25 | | - {{- $widths = $widths | append 1200 -}} |
26 | | - {{- end -}} |
27 | | - {{- if gt $image.Width 1500 -}} |
28 | | - {{- $widths = $widths | append 1500 -}} |
29 | | - {{- end -}} |
30 | | - {{- if gt $image.Width 2200 -}} |
31 | | - {{- $widths = $widths | append 2200 -}} |
32 | | - {{- end -}} |
| 16 | +{{- $widths := slice -}} |
| 17 | +{{- if gt $image.Width 500 -}} |
| 18 | + {{- $widths = $widths | append 500 -}} |
| 19 | +{{- end -}} |
| 20 | +{{- if gt $image.Width 800 -}} |
| 21 | + {{- $widths = $widths | append 800 -}} |
| 22 | +{{- end -}} |
| 23 | +{{- if gt $image.Width 1200 -}} |
| 24 | + {{- $widths = $widths | append 1200 -}} |
| 25 | +{{- end -}} |
| 26 | +{{- if gt $image.Width 1500 -}} |
| 27 | + {{- $widths = $widths | append 1500 -}} |
| 28 | +{{- end -}} |
| 29 | +{{- if gt $image.Width 2200 -}} |
| 30 | + {{- $widths = $widths | append 2200 -}} |
| 31 | +{{- end -}} |
33 | 32 |
|
34 | | - {{- $srcset := slice -}} |
35 | | - {{- range $i, $width := $widths -}} |
36 | | - {{- with $image.Resize (printf "%dx" $width) | resources.Copy (print $name "_" $width "." $extension) -}} |
37 | | - {{- $srcset = $srcset | append (printf "%s %dw" .RelPermalink $width) -}} |
38 | | - {{- end -}} |
| 33 | +{{- $srcset := slice -}} |
| 34 | +{{- range $i, $width := $widths -}} |
| 35 | + {{- with $image.Resize (printf "%dx" $width) | resources.Copy (print $name "_" $width "." $extension) -}} |
| 36 | + {{- $srcset = $srcset | append (printf "%s %dw" .RelPermalink $width) -}} |
39 | 37 | {{- end -}} |
40 | | - {{- $srcset = $srcset | append (printf "%s %dw" $image.RelPermalink $image.Width) -}} |
41 | | - {{- printf "<img src=\"%s\" alt=\"\" loading=\"%s\" srcset=\"%s\" sizes=\"(max-width: 576px) calc(100vw - 3.2rem), (max-width: 768px) 540px, (max-width: 992px) 720px, (max-width: 1200px) 960px, (max-width: 1400px) 1140px, 1320px\">" $image.RelPermalink $loading (delimit $srcset ", ") | safeHTML -}} |
42 | | -</picture> |
| 38 | +{{- end -}} |
| 39 | +{{- $srcset = $srcset | append (printf "%s %dw" $image.RelPermalink $image.Width) -}} |
| 40 | + |
| 41 | +{{- $styles := "" -}} |
| 42 | +{{- if and $image.Width -}} |
| 43 | + {{- $styles = printf "aspect-ratio: %d / %d" $image.Width $image.Height -}} |
| 44 | +{{- end -}} |
| 45 | + |
| 46 | +<img |
| 47 | + src="{{ $image.RelPermalink }}" |
| 48 | + alt="" |
| 49 | + loading="{{ $loading }}" |
| 50 | + srcset="{{ delimit $srcset ", " }}" |
| 51 | + sizes="(max-width: 576px) calc(100vw - 3.2rem), (max-width: 768px) 540px, (max-width: 992px) 720px, (max-width: 1200px) 960px, (max-width: 1400px) 1140px, 1320px" |
| 52 | + style="{{ $styles | safeCSS }}" |
| 53 | +> |
0 commit comments