Skip to content

Commit 8b11be3

Browse files
Refactor spec_meta partial to use theme partials (#599)
1 parent ebbe61a commit 8b11be3

File tree

1 file changed

+39
-60
lines changed

1 file changed

+39
-60
lines changed

layouts/partials/specs/spec_meta.html

Lines changed: 39 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,40 @@
1-
{{ $page := . }}
2-
{{ $isSpec := eq (len (findRE "^spec-\\d*" .File.ContentBaseName)) 1 }}
3-
<div class="sd-card sd-mb-3 sd-shadow-sm">
4-
<div class="sd-card-body">
5-
{{ $meta_fields := (slice "author" "discussion" "history" "endorsed-by") }}
6-
{{ $warn := "" }}
7-
<dl class="field-list">
8-
{{- range $attr := $meta_fields -}}
9-
{{ $val := index $.Params $attr }}
10-
{{ $attr := strings.TrimPrefix "spec_" $attr }}
11-
{{- if eq $attr "author" }}
12-
{{ $attr = "authors" }}
13-
{{- if not (reflect.IsSlice $val) }}
14-
{{ $val = slice $val }}
15-
{{ end }}
16-
{{- else if eq $attr "date" }}
17-
{{ $val = $val.Format "2006-01-02" }}
18-
{{- else if (eq $attr "history") }}
19-
{{ $path := index (split $page.Path "specs/") 1 }}
20-
{{ $link := printf "https://github.com/scientific-python/specs/commits/main/%s" $path }}
21-
{{ $val = printf "<a href=\"%s\">%s</a>" $link $link }}
22-
{{- end -}}
23-
{{ $isSpecField := (in (slice "endorsed-by" "discussion" ) $attr) }}
24-
{{ if (or $isSpec (not $isSpecField)) }}
25-
<dt class="field-odd">
26-
{{ $attr | humanize }}<span class="colon">:</span></dt>
27-
</dt>
28-
{{- if (reflect.IsSlice $val) -}}
29-
{{ $len := len $val }}
30-
<dd class="field-odd">
31-
{{- range $idx, $el := $val }}
32-
{{ if eq $attr "endorsed-by" }}
33-
<a href="{{ relref $.Page.CurrentSection (printf "core-projects/%s" $el) }}">{{ $el }}</a>
34-
{{- else }}
35-
{{ $el }}
36-
{{- end -}}
37-
{{- if not (eq (add $idx 1) $len) -}},{{ end }}
38-
{{ end }}
39-
</dd>
40-
{{- else }}
41-
<dd class="field-odd">
42-
{{ $val | markdownify }}
43-
</dd>
44-
{{- end -}}
45-
{{- end -}}
46-
{{/* add warning that this is a draft, i.e. has not been endorsed by 2 projects or more */}}
47-
{{- if (and (eq $attr "endorsed-by") (lt (len (or $val "")) 2)) -}}
48-
{{ $warn = "True" }}
1+
{{- $filename := .File.ContentBaseName -}}
2+
{{- $endorsed := false -}}
3+
4+
{{/* Create field list */}}
5+
{{- $fieldList := slice -}}
6+
{{- range $term := slice "author" "discussion" "history" "endorsed-by" -}}
7+
{{- $def := index $.Params $term }}
8+
{{- if eq $term "author" }}
9+
{{- $term = "authors" }}
10+
{{- if not (reflect.IsSlice $def) }}
11+
{{- $def = slice $def }}
12+
{{- end }}
13+
{{- $def = delimit $def ", " }}
14+
{{- else if (eq $term "discussion") }}
15+
{{- $def = $def | markdownify }}
16+
{{- else if (eq $term "history") }}
17+
{{- $def = printf "https://github.com/scientific-python/specs/commits/main/%s" $filename | markdownify }}
18+
{{- else if and (eq $term "endorsed-by") (reflect.IsSlice $def) }}
19+
{{- $def = apply $def "printf" "[%s](../core-projects/%s)" "." "." }}
20+
{{- $def = delimit $def ", " }}
21+
{{- $def = $def | markdownify }}
22+
{{- if ge (len $def) 2 -}}
23+
{{ $endorsed = true }}
4924
{{- end -}}
50-
{{- end -}}
51-
</dl>
52-
{{- if $warn }}
53-
<div class="admonition attention">
54-
<div class="admonition-title">
55-
Attention
56-
</div>
57-
<p>This is a draft document.</p>
58-
</div>
59-
{{- end -}}
60-
</div>
61-
</div>
25+
{{- end }}
26+
{{- $fieldList = $fieldList | append (dict "term" ( $term | humanize ) "def" $def ) -}}
27+
{{- end -}}
28+
{{- $specMetaBody := partial "_elements/field-list.html" (dict "entries" $fieldList) -}}
29+
30+
{{/* Add warning if SPEC not endorsed */}}
31+
{{- if not $endorsed }}
32+
{{- $title := "attention" -}}
33+
{{- $body := "This is a draft document." -}}
34+
{{- $admonition := partial "_elements/admonition.html" (dict "title" $title "body" $body) -}}
35+
{{- $specMetaBody = printf "%s %s" $specMetaBody $admonition -}}
36+
{{- end -}}
37+
38+
{{/* Put the SPEC meta data in a card */}}
39+
{{- $card := dict "body" $specMetaBody -}}
40+
{{- partial "_elements/card.html" (dict "card" $card) -}}

0 commit comments

Comments
 (0)