www.byjp.me/layouts/shortcodes/figure.html
2025-07-20 19:40:10 +01:00

26 lines
No EOL
1.2 KiB
HTML

<figure{{ with .Get "class" }} class="{{ . }}"{{ end }}>
{{- if .Get "link" -}}
<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>
{{- end }}
{{ if eq (path.Ext (.Get "src")) ".svg" }}
{{ readFile (path.Join $.Page.File.Dir (.Get "src")) | safeHTML }}
{{ else }}
<img src="{{ path.Join $.Page.RelPermalink (.Get "src") }}"
{{- if or (.Get "alt") (.Get "caption") }}
alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}"
{{- end -}}
{{- with .Get "width" }} width="{{ . }}"{{ end -}}
{{- with .Get "height" }} height="{{ . }}"{{ end -}}
{{- with .Get "usemap" }} usemap="{{ . }}"{{ end -}}
/>
{{ end }}
{{- if .Get "link" }}</a>{{ end -}}
{{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
<figcaption>
{{- default (.Get "title") (.Get "caption") | markdownify -}}
{{- with .Get "attrlink" }}<a href="{{ . }}">{{- end -}}
{{- .Get "attr" | markdownify -}}
{{- if .Get "attrlink" }}</a>{{ end }}</p>
</figcaption>
{{- end }}
</figure>