hugo/docs/layouts/_partials/helpers/picture.html
Bjørn Erik Pedersen 61a286595e
Some checks are pending
Test / test (1.23.x, ubuntu-latest) (push) Waiting to run
Test / test (1.23.x, windows-latest) (push) Waiting to run
Test / test (1.24.x, ubuntu-latest) (push) Waiting to run
Test / test (1.24.x, windows-latest) (push) Waiting to run
Merge commit 'b3d87dd0fd'
2025-04-24 10:23:16 +02:00

27 lines
961 B
HTML

{{ $image := .image }}
{{ $width := .width | default 1000 }}
{{ $width1x := div $width 2 }}
{{ $imageWebp := $image.Resize (printf "%dx webp" $width) }}
{{ $image1x := $image.Resize (printf "%dx" $width1x) }}
{{ $image1xWebp := $image.Resize (printf "%dx webp" $width1x) }}
{{ $class := .class | default "h-64 tablet:h-96 lg:h-full w-full object-cover lg:absolute" }}
{{ $loading := .loading | default "eager" }}
<picture>
<source
srcset="{{ $imageWebp.RelPermalink }}"
type="image/webp"
media="(min-width: 1200px)">
<source
srcset="{{ $image.RelPermalink }}"
type="image/jpeg"
media="(min-width: 1200px)">
<source srcset="{{ $image1xWebp.RelPermalink }}" type="image/webp">
<source srcset="{{ $image1x.RelPermalink }}" type="image/jpeg">
<img
class="{{ $class }}"
src="{{ $image1x.RelPermalink }}"
alt=""
loading="{{ $loading }}"
width="{{ $image1x.Width }}"
height="{{ $image1x.Height }}">
</picture>