FIX browser image selection

This commit is contained in:
Hoernschen 2024-01-13 17:35:12 +01:00
parent 4da5b6d6fd
commit 87d8c05eb2
Signed by: hoernschen
GPG key ID: 37591FAF4E6D3462

View file

@ -2,6 +2,8 @@
type: string - default type: string - default
url: string url: string
alt: string alt: string
width: int
height: int
--> -->
{{ $avatar := "avatar"}} {{ $avatar := "avatar"}}
{{ $sizes := slice "320" "640" "960" "1280" }} {{ $sizes := slice "320" "640" "960" "1280" }}
@ -16,7 +18,7 @@ alt: string
{{ range $i, $size := $sizes }} {{ range $i, $size := $sizes }}
{{ $dir }}/{{ $name }}-{{ $size }}{{ $ext }}.avif {{ $size }}w, {{ $dir }}/{{ $name }}-{{ $size }}{{ $ext }}.avif {{ $size }}w,
{{ end }} {{ end }}
{{ .url }}.avif {{ .url }}.avif {{ .width }}w
" "
/> />
<source <source
@ -25,13 +27,21 @@ alt: string
{{ range $i, $size := $sizes }} {{ range $i, $size := $sizes }}
{{ $dir }}/{{ $name }}-{{ $size }}{{ $ext }}.webp {{ $size }}w, {{ $dir }}/{{ $name }}-{{ $size }}{{ $ext }}.webp {{ $size }}w,
{{ end }} {{ end }}
{{ .url }}.webp {{ .url }}.webp {{ .width }}w
" "
/> />
<img <img
class="{{if eq .type $avatar}}avatar{{end}}" class="{{if eq .type $avatar}}avatar{{end}}"
alt="{{ .alt }}" width="{{ .width }}"
height="{{ .height }}"
srcset="
{{ range $i, $size := $sizes }}
{{ $dir }}/{{ $name }}-{{ $size }}{{ $ext }} {{ $size }}w,
{{ end }}
{{ .url }} {{ .width }}w
"
src="{{ .url }}" src="{{ .url }}"
alt="{{ .alt }}"
loading="lazy" loading="lazy"
decoding="async" decoding="async"
> >