Skip to content

Commit 0126d85

Browse files
authored
update
1 parent d3296a6 commit 0126d85

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

layouts/shortcodes/figure.html

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,25 @@
2222
{{ with $src := $.Page.Resources.GetMatch (.Get "src") }}
2323
<picture>
2424
{{- if $responsiveImages -}}
25+
{{- $imageTypes := slice -}}
2526
{{- 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" -}}
3229
{{- 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 }}" />
3942
{{- end -}}
40-
{{- end -}}, {{$src.Permalink }} {{printf "%dw" ($src.Width)}}" sizes="{{ $dataSzes }}" />
43+
{{- end -}}
4144
{{- end }}
4245
<img loading="lazy" src="{{ $src }}{{- if eq ($align) "center" }}#center{{- end }}"
4346
{{- if or ($alt) ($caption) }}

0 commit comments

Comments
 (0)