Skip to content

Commit 29d60f2

Browse files
author
Ben Zörb
committed
fix(image): adds defaults for type & srcset
1 parent ba4eb60 commit 29d60f2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

hugo-modules/core/utils/asset/image.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,16 @@
5050
{{- $width := .width -}}
5151
{{- $height := .height -}}
5252
{{- range $srcsets -}}
53-
<source sizes="{{- $local_sizes -}}" srcset="{{- .srcset -}}" type="{{- .type -}}">
53+
{{ $srcset := .srcset | default "" }}
54+
{{ $type := .type | default ""}}
55+
<source sizes="{{- $local_sizes -}}" srcset="{{- $srcset -}}" type="{{- $type -}}">
5456
{{- $preload_attr := (dict
5557
"as" "image"
5658
"imagesizes" $local_sizes
57-
"imagesrcset" .srcset
58-
"type" .type
59+
"imagesrcset" $srcset
60+
"type" $type
5961
) -}}
60-
{{- if and $preload (eq .type "image/avif") (not (in ($globals.Scratch.Get "preload") $preload_attr)) -}}
62+
{{- if and $preload (eq $type "image/avif") (not (in ($globals.Scratch.Get "preload") $preload_attr)) -}}
6163
{{- $globals.Scratch.Add "preload" (slice $preload_attr) -}}
6264
{{- end -}}
6365
{{- end -}}
@@ -72,7 +74,7 @@
7274
"href" $src
7375
"type" $mime_type
7476
) -}}
75-
{{- if and $preload (eq .type "image/avif") (not (in ($globals.Scratch.Get "preload") $preload_attr)) -}}
77+
{{- if and $preload (not (in ($globals.Scratch.Get "preload") $preload_attr)) -}}
7678
{{- $globals.Scratch.Add "preload" (slice $preload_attr) -}}
7779
{{- end -}}
7880
{{- end -}}

0 commit comments

Comments
 (0)