render.gno
1.08 Kb · 36 lines
1package flag
2
3import (
4 "strconv"
5 "strings"
6)
7
8// Card renders the standard header of a challenge page: title, grade,
9// category, number of captures and the brief. Authors use it at the top of
10// their Render so every challenge in the cellar reads the same way.
11func Card(info Info, l *Ledger) string {
12 var b strings.Builder
13 b.WriteString("# " + info.Title + "\n\n")
14 b.WriteString("**" + info.Difficulty.String() + "** · " + info.Category)
15 b.WriteString(" · " + strconv.Itoa(l.Count()) + " captured")
16 b.WriteString(" · worth " + strconv.Itoa(Value(info.Difficulty, l.Count())) + " points\n\n")
17 b.WriteString(info.Brief + "\n")
18 return b.String()
19}
20
21// Captures renders the n most recent captures of l as a markdown list.
22func Captures(l *Ledger, n int) string {
23 recent := l.Recent(n)
24 if len(recent) == 0 {
25 return "*Nobody has broken it yet.*\n"
26 }
27 var b strings.Builder
28 for _, c := range recent {
29 b.WriteString("- `" + c.Player.String() + "` at block " + strconv.FormatInt(c.Height, 10))
30 if c.Order == 1 {
31 b.WriteString(" (first)")
32 }
33 b.WriteString("\n")
34 }
35 return b.String()
36}