2026-07-02 00:28:25 -07:00
|
|
|
{{ $id := .Get "id" | default (printf "figure-%d" .Ordinal) }}
|
|
|
|
|
{{ $src := .Get "src" }}
|
|
|
|
|
{{ $caption := .Get "caption" }}
|
|
|
|
|
{{ $alt := .Get "alt" | default $caption }}
|
2026-07-18 19:57:44 -04:00
|
|
|
{{ $width := .Get "width" }}
|
|
|
|
|
{{ $height := .Get "height" }}
|
|
|
|
|
{{ $loading := .Get "loading" | default "lazy" }}
|
|
|
|
|
{{ $fetchpriority := .Get "fetchpriority" }}
|
2026-07-02 00:28:25 -07:00
|
|
|
{{ $figures := .Page.Scratch.Get "figures" | default dict }}
|
|
|
|
|
{{ $number := add (len $figures) 1 }}
|
|
|
|
|
{{ .Page.Scratch.SetInMap "figures" $id $number }}
|
|
|
|
|
|
|
|
|
|
<figure id="{{ $id }}" class="figure">
|
|
|
|
|
{{ with $src }}
|
2026-07-18 19:57:44 -04:00
|
|
|
{{ $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 }}
|
|
|
|
|
<picture class="figure-media">
|
|
|
|
|
{{ with $srcset }}
|
|
|
|
|
<source
|
|
|
|
|
type="image/webp"
|
|
|
|
|
srcset="{{ delimit . ", " }}"
|
|
|
|
|
sizes="(max-width: 860px) calc(100vw - 2rem), 42rem"
|
|
|
|
|
>
|
|
|
|
|
{{ end }}
|
|
|
|
|
<img
|
|
|
|
|
src="{{ . | relURL }}"
|
|
|
|
|
alt="{{ $alt }}"
|
|
|
|
|
{{ with $width }}width="{{ . }}"{{ end }}
|
|
|
|
|
{{ with $height }}height="{{ . }}"{{ end }}
|
|
|
|
|
loading="{{ $loading }}"
|
|
|
|
|
decoding="async"
|
|
|
|
|
{{ with $fetchpriority }}fetchpriority="{{ . }}"{{ end }}
|
|
|
|
|
>
|
|
|
|
|
</picture>
|
2026-07-02 00:28:25 -07:00
|
|
|
{{ end }}
|
|
|
|
|
|
|
|
|
|
{{ if or $caption .Inner }}
|
|
|
|
|
<figcaption>
|
|
|
|
|
<span class="figure-label">Figure {{ $number }}.</span>
|
|
|
|
|
{{ with $caption }}{{ . | markdownify }}{{ else }}{{ .Inner | markdownify }}{{ end }}
|
|
|
|
|
</figcaption>
|
|
|
|
|
{{ end }}
|
|
|
|
|
</figure>
|