main
html 47 lines 2.51 KB
Raw
1 {{- /*
2 Topic / star visualization — a reusable, data-driven chip cloud built from a
3 list of topics. Honest by construction: chips are equal-weight unless an
4 explicit per-topic weight is supplied. Optional star/repo figures are shown as
5 plain text. No third-party assets.
6
7 Params (dict):
8 topics : slice of strings, OR slice of dicts {name, weight} (required)
9 stars : optional total stars figure (number)
10 repos : optional repos-featured figure (number)
11 heading : optional heading text
12 level : optional heading level (default "h2")
13 */ -}}
14 {{- $topics := .topics | default slice -}}
15 {{- $heading := .heading | default "Topics tracked this week" -}}
16 {{- $level := .level | default "h2" | lower -}}
17 {{- if not (in (slice "h2" "h3" "h4" "h5" "h6") $level) }}{{ $level = "h2" }}{{ end -}}
18 {{- /* $level is strictly whitelisted above, so the tag name is safe to emit;
19 the heading text itself remains contextually auto-escaped. */ -}}
20 {{- $hOpen := printf `<%s class="topic-stars__heading">` $level | safeHTML -}}
21 {{- $hClose := printf "</%s>" $level | safeHTML -}}
22 {{- if gt (len $topics) 0 -}}
23 <section class="topic-stars" aria-label="{{ $heading }}">
24 {{ $hOpen }}{{ $heading }}{{ $hClose }}
25 <ul class="topic-stars__cloud">
26 {{- range $topics }}
27 {{- $name := . -}}
28 {{- if reflect.IsMap . }}{{ $name = .name }}{{ end }}
29 {{- /* Topic names are plain, non-interactive labels — no link, no button/pill
30 affordance — so they never look clickable (operator ask, #328). */ -}}
31 <li class="topic-stars__chip">{{ $name }}</li>
32 {{- end }}
33 </ul>
34 {{- /* Coerce repos/stars to integers; .Get from the shortcode yields strings,
35 so accept only digit strings (commas/spaces stripped) and ignore any
36 non-numeric input rather than passing it to lang.FormatNumber. */ -}}
37 {{- $repos := "" -}}{{ with .repos }}{{ $v := printf "%v" . | replaceRE "[, ]" "" }}{{ if findRE "^[0-9]+$" $v }}{{ $repos = $v }}{{ end }}{{ end -}}
38 {{- $stars := "" -}}{{ with .stars }}{{ $v := printf "%v" . | replaceRE "[, ]" "" }}{{ if findRE "^[0-9]+$" $v }}{{ $stars = $v }}{{ end }}{{ end -}}
39 {{- if or $stars $repos }}
40 <p class="topic-stars__figures">
41 {{- with $repos }}<span><strong>{{ lang.FormatNumber 0 (int .) }}</strong> repos featured</span>{{ end }}
42 {{- if and $stars $repos }}<span aria-hidden="true"> · </span>{{ end }}
43 {{- with $stars }}<span><strong>{{ lang.FormatNumber 0 (int .) }}</strong> stars tracked</span>{{ end }}
44 </p>
45 {{- end }}
46 </section>
47 {{- end -}}