hugo-tufte/layouts/shortcodes/figure.html

63 lines
2.1 KiB
HTML
Raw Normal View History

2023-04-18 01:29:12 +02:00
{{ $alt := .Get "alt" | default "Image" }}
2023-04-15 02:53:05 +02:00
{{ $type := .Get "type" | default "normal" }}
{{- $ind := .Get "ind" | default .Site.Params.marginNoteInd -}}
2016-01-15 05:41:16 +01:00
2023-04-18 01:29:12 +02:00
<!-- get a default label just in case -->
{{- $label := printf "%#v" (add .Ordinal 1) | printf "%s%s" "marginfig-" | printf "%s" -}}
{{- if .Get "label" -}}
{{- $label = .Get "label" -}}
{{- end -}}
2023-04-15 02:53:05 +02:00
<!-- begin figure tag -->
2023-04-18 01:29:12 +02:00
{{- if not (eq $type "margin") -}}
{{ if eq $type "full" }}<!-- full -->
2016-01-15 05:41:16 +01:00
<figure class="fullwidth">
2023-04-18 01:29:12 +02:00
{{ else }}<!-- normal -->
<figure {{ with .Get "class" }}class="{{ . }}"{{ end }}>
2016-01-15 05:41:16 +01:00
{{ end }}
2023-04-18 01:29:12 +02:00
{{- end -}}
2016-01-15 05:41:16 +01:00
2023-04-18 01:29:12 +02:00
<!-- begin child elements -->
{{- if eq $type "full" -}}<!-- child for full -->
2016-01-15 05:41:16 +01:00
{{ with .Get "link" }}<a href="{{ . }}">{{ end }}
2023-04-18 01:29:12 +02:00
<img src="{{ .Get "src" }}" alt="{{ $alt }}">
2016-01-15 05:41:16 +01:00
{{ if .Get "link" }}</a>{{ end }}
<figcaption>
2023-04-18 01:29:12 +02:00
{{- else -}}<!-- child for margin or normal (begin) -->
{{- if or (or (.Get "caption") (.Get "attr")) (eq $type "margin") -}}<!-- begin marginnote -->
<label for="{{ $label }}" class="margin-toggle marginnote-ind">{{ $ind }}</label>
2023-04-18 01:29:12 +02:00
<input type="checkbox" id="{{ $label }}" class="margin-toggle"/>
<span class="marginnote">
{{- end -}}
{{- if eq $type "margin" -}}<!-- margin image inside marginnote -->
2016-01-15 05:41:16 +01:00
{{ with .Get "link" }}<a href="{{ . }}">{{ end }}
2023-04-18 01:29:12 +02:00
<img src="{{ .Get "src" }}" alt="{{ $alt }}">
2016-01-15 05:41:16 +01:00
{{ if .Get "link" }}</a>{{ end }}
2023-04-18 01:29:12 +02:00
{{- end -}}
{{- end -}}<!-- child for margin or normal (end) -->
2023-04-15 02:53:05 +02:00
2023-04-18 01:29:12 +02:00
{{ with .Get "title"}}<strong>{{ . | markdownify }}. </strong>{{ end}}
{{ with .Get "caption"}}{{ . | markdownify }}{{ end }}
{{ with .Get "attr" }}{{ . | markdownify }}.{{ end }}
2023-04-15 02:53:05 +02:00
2023-04-18 01:29:12 +02:00
<!-- end child elements -->
{{ if eq $type "full" }}<!-- end full -->
2016-01-15 05:41:16 +01:00
</figcaption>
2023-04-18 01:29:12 +02:00
{{ else }}<!-- end margin or normal -->
{{- if or (or (.Get "caption") (.Get "attr")) (eq $type "margin") -}}</span>{{- end -}}<!-- end marginnote -->
2016-01-15 05:41:16 +01:00
{{ end }}
2023-04-15 02:53:05 +02:00
2023-04-18 01:29:12 +02:00
{{ if (eq $type "normal") }}
2016-01-15 05:41:16 +01:00
{{ with .Get "link" }}<a href="{{ . }}">{{ end }}
2023-04-18 01:29:12 +02:00
<img src="{{ .Get "src" }}" alt="{{ $alt }}">
2016-01-15 05:41:16 +01:00
{{ if .Get "link" }}</a>{{ end }}
{{ end }}
2023-04-15 02:53:05 +02:00
<!-- end figure tag -->
2016-01-15 05:41:16 +01:00
{{ if not (eq $type "margin") }}
</figure>
{{ end }}