Skip to content

Commit 53a8132

Browse files
Add figure functionality for numpy.org (#550)
1 parent 6f41765 commit 53a8132

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

assets/theme-css/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ figure.align-default,
5252
text-align: center;
5353
}
5454

55+
strong.caption-title {
56+
font-weight: bold;
57+
}
58+
5559
.align-left {
5660
text-align: left;
5761
}

layouts/shortcodes/figure.html

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
alt = 'Cute puppies'
88
height = 200
99
width = 200
10-
caption = 'A figure is an image with a caption and/or a legend:'
10+
title = 'Figure title'
11+
attribution = 'Figure Credits: Daily cute puppy image from unslash.com'
12+
attributionlink = 'https://source.unsplash.com/200x200/daily?cute+puppy'
13+
caption = '''
14+
A figure is an image with a caption. Figures may also include a tile, legend, and/or attribution.
15+
'''
1116
legend = '''
1217
**TODO: need to convert yamltotable to tomltotable**
1318

@@ -18,6 +23,8 @@
1823
{{< figure >}}
1924
src = 'https://source.unsplash.com/200x200/daily?cute+puppy'
2025
alt = 'Cute puppies'
26+
attribution = 'from unslash.com'
27+
attributionlink = 'https://source.unsplash.com/200x200/daily?cute+puppy'
2128
align = 'left'
2229
height = 150
2330
width = 150
@@ -36,14 +43,17 @@
3643
{{- $align := default "default" $figure.align -}}
3744
{{- $id := printf "id%03d" $.Ordinal -}}
3845
<figure class="align-{{ $align }}" id="{{ $id }}">
39-
{{- $m := newScratch -}}
40-
{{- $m.Set "image" $figure -}}
41-
{{- $m.SetInMap "image" "align" "center" -}}
42-
{{ partial "_elements/image.html" (dict "data" $m.Values.image) }}
46+
{{ partial "_elements/image.html" (dict "data" $figure) }}
4347
<figcaption>
48+
{{- with $figure.title -}}
49+
<strong class="caption-title">{{ . }}</strong><a class="headerlink" href="#{{ $id }}" title="Link to this image">#</a><br>
50+
{{- end }}
51+
{{- if $figure.attribution -}}
52+
{{- with $figure.attributionlink -}}<a href="{{ . }}">{{- end -}}{{- $figure.attribution -}}{{- if $figure.attributionlink -}}</a>{{- end -}}
53+
{{- end }}
4454
<p><span class="caption-text">
4555
{{- $figure.caption | markdownify -}}
46-
</span><a class="headerlink" href="#{{ $id }}" title="Link to this image">#</a></p>
56+
</span>
4757
{{- with $figure.legend }}
4858
<div class="legend">
4959
{{ . | markdownify -}}

0 commit comments

Comments
 (0)