{{ $id := .Get "id" | default (printf "figure-%d" .Ordinal) }} {{ $src := .Get "src" }} {{ $caption := .Get "caption" }} {{ $alt := .Get "alt" | default $caption }} {{ $width := .Get "width" }} {{ $height := .Get "height" }} {{ $loading := .Get "loading" | default "lazy" }} {{ $fetchpriority := .Get "fetchpriority" }} {{ $figures := .Page.Scratch.Get "figures" | default dict }} {{ $number := add (len $figures) 1 }} {{ .Page.Scratch.SetInMap "figures" $id $number }}
{{ with $src }} {{ $ext := path.Ext . }} {{ $base := strings.TrimSuffix $ext . }} {{ $srcset := slice }} {{ range slice 480 644 768 960 1344 }} {{ $candidate := printf "%s-%d.webp" $base . }} {{ if fileExists (printf "static%s" $candidate) }} {{ $srcset = $srcset | append (printf "%s %dw" ($candidate | relURL) .) }} {{ end }} {{ end }} {{ with $srcset }} {{ end }} {{ $alt }} {{ end }} {{ if or $caption .Inner }}
Figure {{ $number }}. {{ with $caption }}{{ . | markdownify }}{{ else }}{{ .Inner | markdownify }}{{ end }}
{{ end }}