2023-12-23 23:01:53 +00:00
|
|
|
<!--
|
|
|
|
type: string - default
|
|
|
|
url: string
|
|
|
|
alt: string
|
2024-01-13 16:35:12 +00:00
|
|
|
width: int
|
|
|
|
height: int
|
2023-12-23 23:01:53 +00:00
|
|
|
-->
|
2024-01-13 16:15:24 +00:00
|
|
|
{{ $sizes := slice "320" "640" "960" "1280" }}
|
|
|
|
{{ $ext := path.Ext .url }}
|
|
|
|
{{ $name := path.Base (replace .url $ext "") }}
|
|
|
|
{{ $dir := path.Dir .url }}
|
2024-01-08 09:23:35 +00:00
|
|
|
|
|
|
|
<picture>
|
|
|
|
<source
|
|
|
|
type="image/avif"
|
2024-01-13 16:15:24 +00:00
|
|
|
srcset="
|
|
|
|
{{ range $i, $size := $sizes }}
|
|
|
|
{{ $dir }}/{{ $name }}-{{ $size }}{{ $ext }}.avif {{ $size }}w,
|
|
|
|
{{ end }}
|
2024-01-13 16:35:12 +00:00
|
|
|
{{ .url }}.avif {{ .width }}w
|
2024-01-13 16:15:24 +00:00
|
|
|
"
|
2024-01-08 09:23:35 +00:00
|
|
|
/>
|
|
|
|
<source
|
|
|
|
type="image/webp"
|
2024-01-13 16:15:24 +00:00
|
|
|
srcset="
|
|
|
|
{{ range $i, $size := $sizes }}
|
|
|
|
{{ $dir }}/{{ $name }}-{{ $size }}{{ $ext }}.webp {{ $size }}w,
|
|
|
|
{{ end }}
|
2024-01-13 16:35:12 +00:00
|
|
|
{{ .url }}.webp {{ .width }}w
|
2024-01-13 16:15:24 +00:00
|
|
|
"
|
2024-01-08 09:23:35 +00:00
|
|
|
/>
|
|
|
|
<img
|
2024-01-14 11:16:30 +00:00
|
|
|
class="{{ .type }}"
|
2024-01-13 16:35:12 +00:00
|
|
|
width="{{ .width }}"
|
|
|
|
height="{{ .height }}"
|
|
|
|
srcset="
|
|
|
|
{{ range $i, $size := $sizes }}
|
|
|
|
{{ $dir }}/{{ $name }}-{{ $size }}{{ $ext }} {{ $size }}w,
|
|
|
|
{{ end }}
|
|
|
|
{{ .url }} {{ .width }}w
|
|
|
|
"
|
2024-01-08 09:23:35 +00:00
|
|
|
src="{{ .url }}"
|
2024-01-13 16:35:12 +00:00
|
|
|
alt="{{ .alt }}"
|
2024-01-08 09:23:35 +00:00
|
|
|
loading="lazy"
|
|
|
|
decoding="async"
|
|
|
|
>
|
|
|
|
</picture>
|
|
|
|
|
2024-01-06 19:44:35 +00:00
|
|
|
|
|
|
|
{{/* https://www.brycewray.com/posts/2023/05/better-code-image-processing-hugo-render-hook-edition/ */}}
|