Skip to content

Commit 4f80b36

Browse files
authored
Update render-image.html
1 parent 9269432 commit 4f80b36

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- $respSizes := slice 480 720 1080 -}}
1+
{{- $respSizes := slice 720 1080 -}}
22
{{- $dataSzes := "(min-width: 768px) 1080px, 100vw" -}}
33

44
{{- $holder := "GIP" -}}
@@ -14,15 +14,15 @@
1414
{{ with $src := .Page.Resources.GetMatch .Destination }}
1515
{{- if $responsiveImages -}}
1616
<picture>
17+
{{- $imageTypes := slice $src.MediaType.SubType -}}
1718
{{- if and hugo.IsExtended (ne $src.MediaType.Type "image/webp") -}}
18-
<source type="image/webp" srcset="
19-
{{- with $respSizes -}}
20-
{{- range $i, $e := . -}}
21-
{{- if $i }}, {{ end -}}{{- ($src.Resize (print . "x webp " $hint " " $filter) ).RelPermalink | absURL }} {{ . }}w
22-
{{- end -}}
23-
{{- end -}}" sizes="{{ $dataSzes }}" />
19+
{{- $imageTypes = append $imageTypes "webp" -}}
2420
{{- end -}}
25-
<source type="{{ $src.MediaType.Type }}" srcset="
21+
{{- if gt (index $respSizes 0) $src.Width -}}
22+
{{- $respSizes = slice $src.Width -}}
23+
{{- end -}}
24+
{{- range $imageType := $imageTypes -}}
25+
<source type="{{ $imageType }}" srcset="
2626
{{- with $respSizes -}}
2727
{{- range $i, $e := . -}}
2828
{{- if ge $src.Width . -}}
@@ -31,8 +31,9 @@
3131
{{- end -}}
3232
{{- end -}}, {{$src.Permalink }} {{printf "%dw" ($src.Width)}}" sizes="{{ $dataSzes }}" />
3333
<img src="{{ $Destination | safeURL }}" width="{{ .Width }}" height="{{ .Height }}" alt="{{ $Text }}" title="{{ $Title }}" loading="lazy" />
34+
{{- end -}}
3435
</picture>
3536
{{- else }}
3637
<img src="{{ $Destination | safeURL }}" width="{{ $src.Width }}" height="{{ $src.Height }}" alt="{{ $Text }}" title="{{ $Title }}" loading="lazy" />
3738
{{- end }}
38-
{{ end }}
39+
{{ end }}

0 commit comments

Comments
 (0)