Skip to content

Commit 506f8bd

Browse files
Use toml for card data (#468)
* Use yaml for card data * Correct indentation of shortcode output in YAML * Use TOML instead of YAML * Update grid --------- Co-authored-by: Stefan van der Walt <stefanv@berkeley.edu>
1 parent c980ce7 commit 506f8bd

3 files changed

Lines changed: 47 additions & 32 deletions

File tree

layouts/shortcodes/badge.html

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@
2727
{{< /badge >}}
2828

2929
*/}}
30-
3130
<!-- These CSS classes are irregularly named, so the code to translate
3231
into them is a bit awkward. -->
33-
34-
{{ $badge_style := .Get 0 }}
35-
{{ $badge_outline := (eq "outline" (.Get 1)) }}
36-
{{ $badge_variant := (cond $badge_outline "outline" "bg") }}
37-
{{ $badge_variant_text := (cond $badge_outline "text" "bg-text") }}
38-
{{ $badge_label := trim .Inner "\n\r" }}
39-
32+
{{- $badge_style := .Get 0 }}
33+
{{- $badge_outline := (eq "outline" (.Get 1)) }}
34+
{{- $badge_variant := (cond $badge_outline "outline" "bg") }}
35+
{{- $badge_variant_text := (cond $badge_outline "text" "bg-text") }}
36+
{{- $badge_label := trim .Inner "\n\r" -}}
4037
<span class="sd-badge sd-{{$badge_variant}}-{{$badge_style}} sd-{{$badge_variant_text}}-{{$badge_style}}">{{$badge_label}}</span>

layouts/shortcodes/card.html

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,57 @@
22

33
doc: Cards
44

5-
{{< card title="Only heading" >}}{{< /card >}}
5+
{{< card >}}
6+
title = 'Only title'
7+
{{< /card >}}
68

79
{{< card >}}
10+
body = '''
811
Only body.
912

1013
But with multiple text paragraphs.
14+
'''
1115
{{< /card >}}
1216

13-
{{< card title="Heading and body" >}}
17+
{{< card >}}
18+
title = 'Heading and body'
19+
body = '''
1420
Content of the third card.
1521

16-
{{< badge primary >}}
17-
Sample badge
18-
{{< /badge >}}
19-
22+
{{< badge primary >}}Sample badge{{< /badge >}}
23+
'''
2024
{{< /card >}}
2125

2226

23-
{{< card title="Card Title" header="Header" footer="Footer">}}
24-
Card content
27+
{{< card >}}
28+
header = 'Header'
29+
title = 'Card Title'
30+
body = 'Card content'
31+
footer = 'Footer'
2532
{{< /card >}}
2633

27-
2834
*/}}
2935

30-
36+
{{- $data := .Inner | transform.Unmarshal -}}
3137

3238
<div class="bd-content">
3339
<div class="sd-card sd-shadow-sm sd-mb-3">
34-
{{ with .Get "header" }}
35-
<div class="sd-card-header">
36-
{{ . | markdownify }}
37-
</div>
38-
{{ end }}
39-
<div class="sd-card-body">
40-
{{ with .Get "title" }}
40+
{{ with $data.header }}
41+
<div class="sd-card-header">
42+
{{ . | markdownify }}
43+
</div>
44+
{{ end }}
45+
<div class="sd-card-body">
46+
{{ with $data.title }}
4147
<div class="sd-card-title sd-font-weight-bold">
4248
{{ . }}
4349
</div>
4450
{{ end }}
45-
{{ with .Inner }}
51+
{{ with (trim $data.body "\n") }}
4652
{{ . | markdownify }}
4753
{{ end }}
4854
</div>
49-
{{ with .Get "footer" }}
55+
{{ with $data.footer }}
5056
<div class="sd-card-footer">
5157
{{ . | markdownify }}
5258
</div>

layouts/shortcodes/grid.html

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,33 @@
44

55
{{< grid >}}
66

7-
{{< card title="Only heading" >}}{{< /card >}}
7+
{{< card >}}
8+
title = 'Only title'
9+
{{< /card >}}
810

911
{{< card >}}
12+
body = '''
1013
Only body.
1114

1215
But with multiple text paragraphs.
16+
'''
1317
{{< /card >}}
1418

15-
{{< card title="Heading and body" >}}
19+
{{< card >}}
20+
title = 'Heading and body'
21+
body = '''
1622
Content of the third card.
1723

18-
{{< badge primary >}}
19-
Sample badge
20-
{{< /badge >}}
24+
{{< badge primary >}}Sample badge{{< /badge >}}
25+
'''
26+
{{< /card >}}
27+
2128

29+
{{< card >}}
30+
header = 'Header'
31+
title = 'Card Title'
32+
body = 'Card content'
33+
footer = 'Footer'
2234
{{< /card >}}
2335

2436
{{< /grid >}}

0 commit comments

Comments
 (0)