1package config
2
3import (
4 "strconv"
5
6 p "gno.land/p/demo/avl/pager"
7 "gno.land/p/demo/ufmt"
8 "gno.land/p/moul/md"
9 "gno.land/p/moul/realmpath"
10 "gno.land/p/moul/txlink"
11)
12
13var (
14 banner = "---\n[[Leon's Home page]](/r/leon/home) | [[Leon's snippets]](/r/leon/config) | [[GitHub: @leohhhn]](https://github.com/leohhhn)\n\n---"
15 pager = p.NewPager(configs, 10, true)
16)
17
18func Banner() string {
19 return banner
20}
21
22func Render(path string) (out string) {
23 req := realmpath.Parse(path)
24 if req.Path == "" {
25 out += md.H1("Leon's configs & snippets")
26
27 out += ufmt.Sprintf("Leon's main address: %s\n\n", OwnableMain.Owner().String())
28 out += ufmt.Sprintf("Leon's backup address: %s\n\n", OwnableBackup.Owner().String())
29
30 out += md.H2("Snippets")
31
32 if configs.Size() == 0 {
33 out += "No configs yet :c\n\n"
34 } else {
35 page := pager.MustGetPageByPath(path)
36 for _, item := range page.Items {
37 out += ufmt.Sprintf("- [%s](%s:%s)\n\n", item.Value.(Config).name, absPath, item.Key)
38 }
39
40 out += page.Picker()
41 out += "\n\n"
42 out += "Page " + strconv.Itoa(page.PageNumber) + " of " + strconv.Itoa(page.TotalPages) + "\n\n"
43 }
44
45 out += Banner()
46
47 return out
48 }
49
50 return renderConfPage(req.Path)
51}
52
53func renderConfPage(id string) (out string) {
54 raw, ok := configs.Get(id)
55 if !ok {
56 out += md.H1("404")
57 out += "That config does not exist :/"
58 return out
59 }
60
61 conf := raw.(Config)
62 out += md.H1(conf.name)
63 out += ufmt.Sprintf("```\n%s\n```\n\n", conf.lines)
64 out += ufmt.Sprintf("_Last updated on %s_\n\n", conf.updated.Format("02 Jan, 2006"))
65 out += md.HorizontalRule()
66 out += ufmt.Sprintf("[[EDIT]](%s) - [[DELETE]](%s)", txlink.Call("EditConfig", "id", conf.id.String()), txlink.Call("RemoveConfig", "id", conf.id.String()))
67
68 return out
69}
render.gno
1.72 Kb ยท 69 lines