From dbc547c5f0c2b8b751bbe0579c794251611b514f Mon Sep 17 00:00:00 2001 From: Thomas Sindt Date: Tue, 16 Jun 2026 09:10:37 +0200 Subject: [PATCH] image rendering --- .../_default/_markup/render-image.html | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 northsidestudio/themes/basic/layouts/_default/_markup/render-image.html diff --git a/northsidestudio/themes/basic/layouts/_default/_markup/render-image.html b/northsidestudio/themes/basic/layouts/_default/_markup/render-image.html new file mode 100644 index 0000000..248fb18 --- /dev/null +++ b/northsidestudio/themes/basic/layouts/_default/_markup/render-image.html @@ -0,0 +1,41 @@ +{{- $src := .Destination -}} +{{- $alt := .Text -}} +{{- $img := .Page.Resources.GetMatch $src -}} +{{- if not $img -}} + {{- $img = resources.Get $src -}} +{{- end -}} +{{- if $img -}} + {{- $widths := slice 480 768 1024 1366 1920 -}} + {{- $origWidth := $img.Width -}} + {{- $origHeight := $img.Height -}} + {{- $srcsetEntries := slice -}} + {{- range $w := $widths -}} + {{- if le $w $origWidth -}} + {{- $resized := $img.Process (printf "resize %dx webp q85" $w) -}} + {{- $srcsetEntries = $srcsetEntries | append (printf "%s %dw" $resized.RelPermalink $w) -}} + {{- end -}} + {{- end -}} + {{- $fallbackWidth := 1024 -}} + {{- if lt $origWidth 1024 -}} + {{- $fallbackWidth = $origWidth -}} + {{- end -}} + {{- $fallback := $img.Process (printf "resize %dx jpg q85" $fallbackWidth) -}} + {{ $alt }} +{{- else -}} + {{ $alt }} +{{- end -}} +