|
22 | 22 | {{ with $src := $.Page.Resources.GetMatch (.Get "src") }}
|
23 | 23 | <picture>
|
24 | 24 | {{- if $responsiveImages -}}
|
| 25 | + {{- $imageTypes := slice -}} |
25 | 26 | {{- if and hugo.IsExtended (ne $src.MediaType.Type "image/webp") -}}
|
26 |
| - <source type="image/webp" srcset=" |
27 |
| - {{- with $respSizes -}} |
28 |
| - {{- range $i, $e := . -}} |
29 |
| - {{- if $i }}, {{ end -}}{{- ($src.Resize (print . "x webp " $hint " " $filter) ).RelPermalink | absURL }} {{ . }}w |
30 |
| - {{- end -}} |
31 |
| - {{- end -}}" sizes="{{ $dataSzes }}" /> |
| 27 | + {{- $imageTypes = $imageTypes | append "avif" -}} // avif need the first |
| 28 | + {{- $imageTypes = $imageTypes | append "webp" -}} |
32 | 29 | {{- end -}}
|
33 |
| - <source type="{{ $src.MediaType.Type }}" srcset=" |
34 |
| - {{- with $respSizes -}} |
35 |
| - {{- range $i, $e := . -}} |
36 |
| - {{- if ge $src.Width . -}} |
37 |
| - {{- if $i }}, {{ end -}}{{- ($src.Resize (print . "x jpg " $filter) ).RelPermalink | absURL}} {{ . }}w |
38 |
| - {{- end -}} |
| 30 | + {{- range $imageType := $imageTypes -}} |
| 31 | + <source type="image/{{ $imageType }}" srcset=" |
| 32 | + {{- $compressedImage := printf "%s_1080x.%s" $Destination $imageType -}} |
| 33 | + {{- $cmSrc := $Page.Resources.GetMatch $compressedImage -}} |
| 34 | + {{- if $cmSrc -}} |
| 35 | + {{ $cmSrc.RelPermalink | absURL}} 1080w |
| 36 | + {{- else -}} |
| 37 | + {{- with $respSizes -}} |
| 38 | + {{- range $i, $e := . -}} |
| 39 | + {{- if $i }}, {{ end -}}{{- ($src.Resize (print . "x " $imageType $hint " " $filter) ).RelPermalink | absURL }} {{ . }}w |
| 40 | + {{- end -}} |
| 41 | + {{- end -}}" sizes="{{ $dataSzes }}" /> |
39 | 42 | {{- end -}}
|
40 |
| - {{- end -}}, {{$src.Permalink }} {{printf "%dw" ($src.Width)}}" sizes="{{ $dataSzes }}" /> |
| 43 | + {{- end -}} |
41 | 44 | {{- end }}
|
42 | 45 | <img loading="lazy" src="{{ $src }}{{- if eq ($align) "center" }}#center{{- end }}"
|
43 | 46 | {{- if or ($alt) ($caption) }}
|
|
0 commit comments