|
1 | 1 | {{/* layouts/shortcodes/tmfigure.html */}} |
2 | | -{{- $figureStyleParts := slice "padding-top: 0.5em;" -}} |
| 2 | +{{- $figureStyleParts := slice -}} |
| 3 | +{{- if not (eq (.Get "centered") "true") -}} |
| 4 | + {{- $figureStyleParts = $figureStyleParts | append "padding-top: 0.5em;" -}} |
| 5 | +{{- end -}} |
3 | 6 | {{- with .Get "style" -}} |
4 | 7 | {{- $figureStyleParts = $figureStyleParts | append . -}} |
5 | 8 | {{- end -}} |
| 9 | +{{- if eq (.Get "centered") "true" -}} |
| 10 | + {{- $figureStyleParts = $figureStyleParts | append "text-align: center;" -}} |
| 11 | +{{- end -}} |
| 12 | +{{- with .Get "float" -}} |
| 13 | + {{- $figureStyleParts = $figureStyleParts | append (printf "float: %s;" .) -}} |
| 14 | + {{- if eq . "left" -}} |
| 15 | + {{- $figureStyleParts = $figureStyleParts | append "margin: 0 1.5rem 1rem 0;" -}} |
| 16 | + {{- else if eq . "right" -}} |
| 17 | + {{- $figureStyleParts = $figureStyleParts | append "margin: 0 0 1rem 1.5rem;" -}} |
| 18 | + {{- end -}} |
| 19 | + {{- with $.Get "width" -}} |
| 20 | + {{- $figureStyleParts = $figureStyleParts | append (printf "width: %s;" .) -}} |
| 21 | + {{- end -}} |
| 22 | +{{- end -}} |
6 | 23 | {{- $figureStyleAttr := printf ` style="%s"` (delimit $figureStyleParts " ") -}} |
7 | 24 | <figure{{ with .Get "class" }} class="{{ . }}"{{ end }}{{ $figureStyleAttr | safeHTMLAttr }}> |
8 | 25 | {{- if .Get "link" -}} |
9 | 26 | <a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}> |
10 | 27 | {{- end }} |
11 | | - |
| 28 | + |
12 | 29 | {{- with $src := .Get "src" }} |
13 | 30 | {{- $resource := $.Page.Resources.GetMatch $src -}} |
14 | 31 | {{- with $resource }} |
|
23 | 40 | {{- $heightIsNumber := and $height (findRE "^[0-9]+$" $height) -}} |
24 | 41 | {{- $styleParts := slice -}} |
25 | 42 | {{- if and $width (not $widthIsNumber) -}} |
26 | | - {{- $styleParts = $styleParts | append (printf "width: %s;" $width) -}} |
| 43 | + {{- if $.Get "float" -}} |
| 44 | + {{- $styleParts = $styleParts | append "width: 100%;" -}} |
| 45 | + {{- else -}} |
| 46 | + {{- $styleParts = $styleParts | append (printf "width: %s;" $width) -}} |
| 47 | + {{- end -}} |
27 | 48 | {{- end -}} |
28 | 49 | {{- if and $height (not $heightIsNumber) -}} |
29 | 50 | {{- $styleParts = $styleParts | append (printf "height: %s;" $height) -}} |
30 | 51 | {{- end -}} |
31 | 52 | {{- if and $width (not $height) -}} |
32 | 53 | {{- $styleParts = $styleParts | append "height: auto;" -}} |
33 | 54 | {{- end -}} |
34 | | - {{- $styleParts = $styleParts | append "display: block;" "margin-left: auto;" "margin-right: auto;" -}} |
| 55 | + {{- $styleParts = $styleParts | append "display: block;" -}} |
| 56 | + {{- if not ($.Get "float") -}} |
| 57 | + {{- $styleParts = $styleParts | append "margin-left: auto;" "margin-right: auto;" -}} |
| 58 | + {{- end -}} |
| 59 | + {{- if eq ($.Get "rounded") "true" -}} |
| 60 | + {{- $styleParts = $styleParts | append "border-radius: 10px;" -}} |
| 61 | + {{- end -}} |
35 | 62 | {{- $styleAttr := "" -}} |
36 | 63 | {{- if gt (len $styleParts) 0 -}} |
37 | 64 | {{- $styleAttr = printf ` style="%s"` (delimit $styleParts " ") -}} |
|
49 | 76 | /> |
50 | 77 | {{- end -}} |
51 | 78 | {{- end }} |
52 | | - |
| 79 | + |
53 | 80 | {{- if .Get "link" }}</a>{{ end -}} |
54 | | - |
| 81 | + |
55 | 82 | {{- if or (.Get "title") (.Get "caption") (.Get "attr") .Inner -}} |
56 | | - <figcaption style="font-size: 90%; padding: 0.5em 1.5em; line-height: 1.4;"> |
| 83 | + {{- $captionStyle := "font-size: 80%; padding: 0.5em 1.5em; line-height: 1.4;" -}} |
| 84 | + {{- if eq ($.Get "centered") "true" -}} |
| 85 | + {{- $captionStyle = printf "%s %s" $captionStyle "font-style: italic; color: var(--gray-500); margin-top: 0.4rem;" -}} |
| 86 | + {{- end -}} |
| 87 | + {{- $captionStyleAttr := printf ` style="%s"` $captionStyle -}} |
| 88 | + <figcaption{{ $captionStyleAttr | safeHTMLAttr }}> |
57 | 89 | {{ with (.Get "title") -}} |
58 | 90 | <h4 style="margin-bottom: 0.5em;">{{ . }}</h4> |
59 | 91 | {{- end -}} |
60 | | - |
| 92 | + |
61 | 93 | {{ $caption := or (.Get "caption") .Inner }} |
62 | 94 | {{ with $caption }} |
63 | 95 | {{/* (?s) enables "dot matches newline" mode to catch multi-line P tags */}} |
|
0 commit comments