summaryrefslogtreecommitdiff
path: root/layouts/_default/_markup/render-image.html
diff options
context:
space:
mode:
Diffstat (limited to 'layouts/_default/_markup/render-image.html')
-rwxr-xr-xlayouts/_default/_markup/render-image.html28
1 files changed, 27 insertions, 1 deletions
diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html
index 0a338b6..9bd482e 100755
--- a/layouts/_default/_markup/render-image.html
+++ b/layouts/_default/_markup/render-image.html
@@ -1 +1,27 @@
-<img src="{{ .Page.Permalink }}{{ .Destination }}"{{ with .Text }} alt="{{ . | safeHTML }}" title="{{ . | safeHTML }}"{{- end -}}>
+{{ $src := .Page.Resources.GetMatch (printf "%s" (.Destination | safeURL)) }}
+
+{{ if $src }}
+<figure>
+ {{ $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}}