Skip to content

Commit 74580a2

Browse files
committed
use tmfigure throughout - deprecate image_with_source
1 parent 273212e commit 74580a2

6 files changed

Lines changed: 60 additions & 33 deletions

File tree

assets/_custom.scss

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,24 +172,6 @@ figure.big-figure img {
172172
display: block;
173173
}
174174

175-
/* Image with source caption */
176-
figure.image-with-source {
177-
text-align: center;
178-
margin: $padding-16 0;
179-
180-
img {
181-
max-width: 100%;
182-
height: auto;
183-
border-radius: 10px;
184-
}
185-
186-
figcaption {
187-
font-size: $font-size-12;
188-
font-style: italic;
189-
color: var(--gray-500);
190-
margin-top: 0.4rem;
191-
}
192-
}
193175

194176
// Blog post title links: use heading color
195177
.book-post h1 a,

assets/_shortcodes.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@
102102
}
103103
}
104104

105+
// {{< tmfigure float="left/right" >}}
106+
figure[style*="float"] {
107+
max-width: 45%;
108+
}
109+
110+
.clearfix::after {
111+
content: "";
112+
display: table;
113+
clear: both;
114+
}
115+
105116
// {{< globe >}}
106117
.globe-embed {
107118
width: 100%;

content/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ weight: 1
55
bookToc: false
66
---
77

8-
{{< image_with_source src="/images/orbital_rays.jpg" alt="First rays of an orbital sunrise" link="https://www.nasa.gov/image-detail/first-rays-of-an-orbital-sunrise/" source="NASA" >}}
8+
{{< tmfigure src="/images/orbital_rays.jpg" alt="First rays of an orbital sunrise" caption="Source: [NASA](https://www.nasa.gov/image-detail/first-rays-of-an-orbital-sunrise/)" rounded="true" centered="true" >}}{{< /tmfigure >}}
99

1010
## Hello 👋
1111

layouts/posts/single.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
{{ define "main" }}
22
<article class="markdown book-post">
3+
{{ with .Params.cover }}
4+
<figure style="text-align: center; margin-bottom: 1rem;">
5+
<img src="{{ .src }}" alt="{{ .alt }}" style="display: block; margin-left: auto; margin-right: auto; border-radius: 10px;">
6+
<figcaption style="font-size: 90%; padding: 0.5em 1.5em; line-height: 1.4; font-style: italic; color: var(--gray-500); margin-top: 0.4rem;">
7+
Source: <a href="{{ .link }}" target="_blank">{{ .source }}</a>
8+
</figcaption>
9+
</figure>
10+
{{ end }}
311
<h1>
412
<a href="{{ .RelPermalink }}">{{ partial "docs/title.html" . }}</a>
513
</h1>

layouts/shortcodes/image_with_source.html

Lines changed: 0 additions & 6 deletions
This file was deleted.

layouts/shortcodes/tmfigure.html

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
{{/* 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 -}}
36
{{- with .Get "style" -}}
47
{{- $figureStyleParts = $figureStyleParts | append . -}}
58
{{- 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 -}}
623
{{- $figureStyleAttr := printf ` style="%s"` (delimit $figureStyleParts " ") -}}
724
<figure{{ with .Get "class" }} class="{{ . }}"{{ end }}{{ $figureStyleAttr | safeHTMLAttr }}>
825
{{- if .Get "link" -}}
926
<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>
1027
{{- end }}
11-
28+
1229
{{- with $src := .Get "src" }}
1330
{{- $resource := $.Page.Resources.GetMatch $src -}}
1431
{{- with $resource }}
@@ -23,15 +40,25 @@
2340
{{- $heightIsNumber := and $height (findRE "^[0-9]+$" $height) -}}
2441
{{- $styleParts := slice -}}
2542
{{- 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 -}}
2748
{{- end -}}
2849
{{- if and $height (not $heightIsNumber) -}}
2950
{{- $styleParts = $styleParts | append (printf "height: %s;" $height) -}}
3051
{{- end -}}
3152
{{- if and $width (not $height) -}}
3253
{{- $styleParts = $styleParts | append "height: auto;" -}}
3354
{{- 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 -}}
3562
{{- $styleAttr := "" -}}
3663
{{- if gt (len $styleParts) 0 -}}
3764
{{- $styleAttr = printf ` style="%s"` (delimit $styleParts " ") -}}
@@ -49,15 +76,20 @@
4976
/>
5077
{{- end -}}
5178
{{- end }}
52-
79+
5380
{{- if .Get "link" }}</a>{{ end -}}
54-
81+
5582
{{- 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 }}>
5789
{{ with (.Get "title") -}}
5890
<h4 style="margin-bottom: 0.5em;">{{ . }}</h4>
5991
{{- end -}}
60-
92+
6193
{{ $caption := or (.Get "caption") .Inner }}
6294
{{ with $caption }}
6395
{{/* (?s) enables "dot matches newline" mode to catch multi-line P tags */}}

0 commit comments

Comments
 (0)