Inline image template

This is for embedding SVGs inline.
This commit is contained in:
Eryn Wells 2025-01-04 10:12:29 -08:00
parent 05956b83b8
commit 7d56bd2f78

View file

@ -0,0 +1,24 @@
{{- $image := .page.Resources.GetMatch .name -}}
{{ if not $image }}
{{ errorf "No images named '%s' found. %s " .name .page.Permalink }}
{{ end }}
{{ if ne $image.MediaType.SubType "svg" }}
{{ errorf "Only SVGs may be inlined. %s" $image.Permalink }}
{{ end }}
{{- $classes := slice "figure" "figure--image" "figure--inline-image" -}}
{{- if eq .size "main" -}}
{{ $classes = $classes | append "figure--main-column" }}
{{- end -}}
{{- with .class -}}
{{ $classes = $classes | append . }}
{{- end -}}
<figure class="{{ delimit $classes " " }}">
{{ $image.Content | safeHTML }}
{{ if .shouldShowTitle }}
{{ partial "page/figures/caption.html" (merge . (dict "resource" $image)) }}
{{ end }}
</figure>