Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add figure functionality for numpy.org #550

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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