Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

render.gno

1.58 Kb · 49 lines
 1package releases
 2
 3import (
 4	"strconv"
 5
 6	"gno.land/p/moul/kit/ui/v0"
 7	"gno.land/p/moul/md/v0"
 8	"gno.land/p/moul/realmpath/v0"
 9	"chain/runtime"
10)
11
12// untrusted-render: every owner string is escaped by p/moul/releases where it builds the markdown, and project names are a-z0-9- checked at write time
13
14// Render serves the index of projects at "", a project's stage homepage at
15// "<project>", and one release at "<project>/<version>". Every owner string is
16// escaped by the library, which is where the markdown is built.
17func Render(path string) string {
18	req := realmpath.Parse(path)
19	name := req.PathPart(0)
20	if name == "" {
21		return renderIndex()
22	}
23	e := lookup(name)
24	if e == nil {
25		return ui.Empty("No such project.")
26	}
27	height := runtime.ChainHeight()
28	if v := req.PathPart(1); v != "" {
29		return e.project.RenderRelease(v, height) + "\n" + md.Link("All versions", StageURL(name)) + "\n"
30	}
31	return e.project.RenderStage(height, func(v string) string { return StageURL(name) + "/" + v })
32}
33
34func renderIndex() string {
35	out := md.H1("Releases") + "\n"
36	out += "Which version of each project is the latest, and what the others may still do. " +
37		"A version asks this realm on every write and every render.\n\n"
38	t := ui.NewTable("project", "latest", "versions", "owner")
39	for i := 0; i < projects.Size(); i++ {
40		name, v := projects.GetByIndex(i)
41		e := v.(*entry)
42		latest := "none"
43		if r, ok := e.project.Latest(); ok {
44			latest = md.Link(r.Version, r.Link())
45		}
46		t.Row(md.Link(name, StageURL(name)), latest, strconv.Itoa(e.project.Size()), ui.Addr(e.owner))
47	}
48	return out + t.OrEmpty("No projects yet.")
49}