night0721.xyz/layouts/_default/_markup/render-image.html

26 lines
945 B
HTML
Raw Permalink Normal View History

2023-11-07 21:55:50 +01:00
{{ $src := .Page.Resources.GetMatch (printf "%s" (.Destination | safeURL)) }}
{{ if $src }}
<figure class="full-width">
{{ $data := newScratch }}
{{ if gt $src.Width 1100 }}
{{ $data.Set "webp" ($src.Resize "960x webp q90") }}
{{ $data.Set "fallback" ($src.Resize "960x q90") }}
{{ else }}
{{ $data.Set "webp" ($src.Resize (printf "%dx%d webp q90" $src.Width $src.Height)) }}
{{ $data.Set "fallback" ($src.Resize (printf "%dx%d q90" $src.Width $src.Height)) }}
{{ end }}
{{ $webp := $data.Get "webp" }}
{{ $fallback := $data.Get "fallback" }}
<a href="{{ $src }}">
<picture>
<source srcset="{{ $webp.RelPermalink }}" type="image/webp">
<img src="{{ $fallback.RelPermalink }}" alt="{{ .Text }}" loading="lazy" decoding="async" width="{{ $src.Width }}" height="{{ $src.Height }}" />
</picture>
</a>
{{ with .Title }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }}
</figure>
{{end}}