Skip to content

Commit

Permalink
Add figure functionality for numpy.org (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrodmillman authored Mar 19, 2024
1 parent 6f41765 commit 53a8132
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions assets/theme-css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ figure.align-default,
text-align: center;
}

strong.caption-title {
font-weight: bold;
}

.align-left {
text-align: left;
}
Expand Down
22 changes: 16 additions & 6 deletions layouts/shortcodes/figure.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
alt = 'Cute puppies'
height = 200
width = 200
caption = 'A figure is an image with a caption and/or a legend:'
title = 'Figure title'
attribution = 'Figure Credits: Daily cute puppy image from unslash.com'
attributionlink = 'https://source.unsplash.com/200x200/daily?cute+puppy'
caption = '''
A figure is an image with a caption. Figures may also include a tile, legend, and/or attribution.
'''
legend = '''
**TODO: need to convert yamltotable to tomltotable**

Expand All @@ -18,6 +23,8 @@
{{< figure >}}
src = 'https://source.unsplash.com/200x200/daily?cute+puppy'
alt = 'Cute puppies'
attribution = 'from unslash.com'
attributionlink = 'https://source.unsplash.com/200x200/daily?cute+puppy'
align = 'left'
height = 150
width = 150
Expand All @@ -36,14 +43,17 @@
{{- $align := default "default" $figure.align -}}
{{- $id := printf "id%03d" $.Ordinal -}}
<figure class="align-{{ $align }}" id="{{ $id }}">
{{- $m := newScratch -}}
{{- $m.Set "image" $figure -}}
{{- $m.SetInMap "image" "align" "center" -}}
{{ partial "_elements/image.html" (dict "data" $m.Values.image) }}
{{ partial "_elements/image.html" (dict "data" $figure) }}
<figcaption>
{{- with $figure.title -}}
<strong class="caption-title">{{ . }}</strong><a class="headerlink" href="#{{ $id }}" title="Link to this image">#</a><br>
{{- end }}
{{- if $figure.attribution -}}
{{- with $figure.attributionlink -}}<a href="{{ . }}">{{- end -}}{{- $figure.attribution -}}{{- if $figure.attributionlink -}}</a>{{- end -}}
{{- end }}
<p><span class="caption-text">
{{- $figure.caption | markdownify -}}
</span><a class="headerlink" href="#{{ $id }}" title="Link to this image">#</a></p>
</span>
{{- with $figure.legend }}
<div class="legend">
{{ . | markdownify -}}
Expand Down

0 comments on commit 53a8132

Please sign in to comment.