Author: Adam Evyčędo <git@apiote.xyz>
initial
go.mod | 5 ++ go.sum | 26 ++++++++++++ roadmap.go | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ task.html | 26 ++++++++++++
diff --git a/go.mod b/go.mod new file mode 100644 index 0000000000000000000000000000000000000000..2c13714de218aa3e24040932d48ffe52d0d7fd19 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module apiote.xyz/p/roadmap + +go 1.23 + +require github.com/rveen/ogdl v1.2.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000000000000000000000000000000000000..caa397a5453f1cc9bec0bb824e350dc93a840573 --- /dev/null +++ b/go.sum @@ -0,0 +1,26 @@ +github.com/rveen/ogdl v1.2.0 h1:nIOBvd3o2Ln1aQmwa6U6vm/So15HZUetiDvOe7VepgU= +github.com/rveen/ogdl v1.2.0/go.mod h1:+k+Xap8qXTEaKIpj/SuKw8Xjvyp/KuECLvci0AVI7lY= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/roadmap.go b/roadmap.go new file mode 100644 index 0000000000000000000000000000000000000000..a353f2c59d4eefc016f8a1705fa29dca4d428b6c --- /dev/null +++ b/roadmap.go @@ -0,0 +1,119 @@ +package main + +import ( + "errors" + "fmt" + "html" + "io/fs" + "log" + "net/http" + "os" + "path/filepath" + "strings" + + "github.com/rveen/ogdl" +) + +type Task struct { + Path string + Summary string + + Subtasks []Task +} + +func main() { + base := "" + if len(os.Args) < 2 { + // TODO error + os.Exit(1) + } else { + base = os.Args[1] + } + + base = filepath.Clean(base) + router(base) +} + +func router(base string) { + http.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) { + body := renderTasks(base, filepath.Clean(r.URL.Path)) + rw.Write([]byte(body)) + }) + + http.ListenAndServe(":8080", nil) +} + +func renderTasks(base, path string) string { + if path == "/" { + t, err := root(base) + if err != nil { + log.Printf("while getting task %s: %v", path, err) + return "" // TODO render error + } + log.Println(t) + return "" // TODO render task + } else { + t, err := task(base, path) + if err != nil { + log.Printf("while getting task %s: %v", path, err) + return "" // TODO render error + } + fmt.Println(t) + return "" // TODO render task + } +} + +func root(base string) ([]Task, error) { + tasks := []Task{} + dirEntries, err := os.ReadDir(base) + if err != nil { + log.Printf("while reading dir: %v", err) + os.Exit(1) + } + + for _, dirEntry := range dirEntries { + if !dirEntry.IsDir() { + task, err := readTask(base, dirEntry.Name()) + if err != nil { + return []Task{}, fmt.Errorf("while reading dir: %v", err) + } + tasks = append(tasks, task) + } + } + return tasks, nil +} + +func task(base, path string) (Task, error) { + task, err := readTask(base, path+".ogdl") + if err != nil { + return Task{}, fmt.Errorf("while reading task %s: %v", path, err) + } + dirEntries, err := os.ReadDir(filepath.Join(base, path)) + if err != nil { + if errors.Is(err, fs.ErrNotExist) { + return task, nil + } + return Task{}, fmt.Errorf("while reading dir: %v", err) + } + for _, dirEntry := range dirEntries { + if !dirEntry.IsDir() { + subtask, err := readTask(base, filepath.Join(path, dirEntry.Name())) + if err != nil { + return Task{}, fmt.Errorf("while reading subtask %s: %v", path, err) + } + task.Subtasks = append(task.Subtasks, subtask) + } + } + return task, nil +} + +func readTask(base, path string) (Task, error) { + g := ogdl.FromFile(filepath.Join(base, path)) + if g == nil { + return Task{}, fmt.Errorf("no such task: %s", path) + } + return Task{ + Path: strings.ReplaceAll(path, ".ogdl", ""), + Summary: g.String(), + }, nil +} diff --git a/task.html b/task.html new file mode 100644 index 0000000000000000000000000000000000000000..e96ae0d0422a9aa7828da615ace7cbe2fe966cb7 --- /dev/null +++ b/task.html @@ -0,0 +1,26 @@ +<!DOCTYPE html> +<html> + <head> + <title>Roadmap {.Path}</title> + </head> + <body> + <nav>{{ .Path }}</path> + <h1>{{ .Summary }}</h1> + <p>{{ .Status }}</p> <!-- assignee --> + <p>#{{ .Tags }}</p> + <p>{{ .Description }}</p> + <hr/> + <div> <!-- flex --> + {{ range .Statuses }} + <div> <!-- inline --> + <div>{{ . }}</div> + {{ range .Subtasks.{{.}} }} <!-- func ret: map[status][]Task, tasks sorted by priority --> + <div> + <a href="{{ .Path }}">{{ .Path }}</a> + <p>{{ .Summary }}</p> + <!-- what else: tags, assignee --> + </div> + </div> + </div> + </body> +</html>