xonecas.io
8356
Wx

www-xonecas-io / commit 08604d8

file browser gets a sidebar tree, opened along the current path (1016)

Co-Authored-By: Claude Opus 5.5

Sean Caetano Martin2026-11-08 08604d82fdfb808dd234b4c4363b37219a06018a parent da02332

5 files changed

internal/site/browse.go+4−2
@@ -33,6 +33,7 @@ type BrowsePage struct {
3333 Name string
3434 Path string
3535 Crumbs []Crumb
36+ Side []SideEntry // the sidebar
3637 Entries []TreeEntry // a folder's contents
3738 Code template.HTML // a file, highlighted
3839 Size string // a file's size
@@ -56,8 +57,9 @@ func writeBrowse(out string, p project.Project, row ProjectRow, t Tree, fresh bo
5657 return err
5758 }
5859 }
60+ kids := children(p.Name, t)
5961 for d := range t.Dirs {
60- page := BrowsePage{Row: row, Name: p.Name, Path: d, Crumbs: crumbs(p.Name, d), Entries: entries(p.Name, d, t)}
62+ page := BrowsePage{Row: row, Name: p.Name, Path: d, Crumbs: crumbs(p.Name, d), Side: sidebar(kids, d), Entries: kids[d]}
6163 if err := render(filepath.Join(base, "tree", filepath.FromSlash(d), "index.html"), "browse.html", page); err != nil {
6264 return err
6365 }
@@ -69,7 +71,7 @@ func writeBrowse(out string, p project.Project, row ProjectRow, t Tree, fresh bo
6971 wg.Go(func() {
7072 sem <- struct{}{}
7173 defer func() { <-sem }()
72- page := BrowsePage{Row: row, Name: p.Name, Path: f, Crumbs: crumbs(p.Name, f), Size: bytesize(size)}
74+ page := BrowsePage{Row: row, Name: p.Name, Path: f, Crumbs: crumbs(p.Name, f), Side: sidebar(kids, f), Size: bytesize(size)}
7375 if size > MaxShow {
7476 page.Note = "Too big to show."
7577 } else if b, err := repo.Blob(dir, "HEAD:"+f); err != nil {
internal/site/sidebar.go+41−0
@@ -0,0 +1,41 @@
1+package site
2+
3+import (
4+ "path"
5+ "strings"
6+)
7+
8+// SideEntry is one line of the file browser's sidebar, indented by its depth.
9+type SideEntry struct {
10+ TreeEntry
11+ Depth int
12+ Here bool // the page being shown
13+ Open bool // a folder whose entries follow
14+}
15+
16+// children is every folder's entries in t, keyed by folder ("" for the root).
17+func children(name string, t Tree) map[string][]TreeEntry {
18+ kids := map[string][]TreeEntry{"": entries(name, "", t)}
19+ for d := range t.Dirs {
20+ kids[d] = entries(name, d, t)
21+ }
22+ return kids
23+}
24+
25+// sidebar is the root's entries, with every folder on the way to path p opened.
26+func sidebar(kids map[string][]TreeEntry, p string) []SideEntry {
27+ var list []SideEntry
28+ var walk func(dir string, depth int)
29+ walk = func(dir string, depth int) {
30+ for _, e := range kids[dir] {
31+ q := path.Join(dir, e.Name)
32+ open := e.Dir && (q == p || strings.HasPrefix(p, q+"/"))
33+ list = append(list, SideEntry{e, depth, q == p, open})
34+ if open {
35+ walk(q, depth+1)
36+ }
37+ }
38+ }
39+ walk("", 0)
40+ return list
41+}
internal/site/sidebar_test.go+18−0
@@ -0,0 +1,18 @@
1+package site
2+
3+import (
4+ "fmt"
5+ "testing"
6+)
7+
8+// TestSidebar opens only the folders on the way to the page, and marks the page.
9+func TestSidebar(t *testing.T) {
10+ tree := Tree{Files: map[string]int64{"a/b/c.go": 1, "a/d.go": 1, "e/f.go": 1, "g.md": 1}, Dirs: map[string]bool{"a": true, "a/b": true, "e": true}}
11+ got := ""
12+ for _, e := range sidebar(children("p", tree), "a/b/c.go") {
13+ got += fmt.Sprintf("%d%s%v ", e.Depth, e.Name, e.Here || e.Open)
14+ }
15+ if want := "0atrue 1btrue 2c.gotrue 1d.gofalse 0efalse 0g.mdfalse "; got != want {
16+ t.Errorf("got %q, want %q", got, want)
17+ }
18+}
internal/site/templates/browse.html+7−0
@@ -1,6 +1,11 @@
11 {{define "browse.html"}}{{template "head" (printf "%s · %s" .Path .Name)}}{{template "nav" "Projects"}}
22 <main class="px-4 sm:px-8 py-6 max-w-[1440px] mx-auto">
33 {{template "project-head" (dict "Row" .Row "Here" "files")}}
4+ <div class="lg:grid lg:grid-cols-[16rem_minmax(0,1fr)] lg:gap-6">
5+ <nav class="hidden lg:block sticky top-4 self-start max-h-[calc(100vh-2rem)] overflow-y-auto [scrollbar-width:thin] font-mono text-[13px] leading-6">
6+ {{range .Side}}<a href="{{.Href}}" style="padding-left: {{.Depth}}rem" class="block truncate no-underline hover:underline {{if .Here}}font-bold text-accent{{else if .Dir}}font-semibold{{end}}">{{if .Open}}▾ {{else if .Dir}}▸ {{else}}· {{end}}{{.Name}}{{if .Dir}}/{{end}}</a>{{end}}
7+ </nav>
8+ <div class="min-w-0">
49 <p class="font-mono text-sm mb-3 break-all">{{range $i, $c := .Crumbs}}{{if $i}} / {{end}}{{if eq (inc $i) (len $.Crumbs)}}<b>{{$c.Name}}</b>{{else}}<a href="{{$c.Href}}">{{$c.Name}}</a>{{end}}{{end}}</p>
510 {{if .Entries}}{{template "file-tree" (dict "Entries" .Entries)}}
611 {{else}}<div class="border-[1.5px] border-ink rounded-[2px] bg-card overflow-hidden">
@@ -8,5 +13,7 @@
813 {{with .Note}}<p class="px-4 py-6 font-serif italic text-soft">{{.}}</p>
914 {{else}}<div class="bg-pre text-pre-fg overflow-x-auto [scrollbar-width:thin] font-mono text-[12.5px] leading-relaxed py-2">{{.Code}}</div>{{end}}
1015 </div>{{end}}
16+ </div>
17+ </div>
1118 </main>
1219 {{template "foot"}}{{end}}
tickets/1016-browsing-files-should-have-a-sidebar-for-easier.md+13−3
@@ -2,13 +2,13 @@
22 id: 1016
33 title: Browsing files should have a sidebar for easier navigation
44 type: feature
5-status: doing
5+status: review
66 priority: p2
77 created: 2026-11-08T03:49:32Z
8-updated: 2026-11-08T04:02:20Z
8+updated: 2026-11-08T04:20:55Z
99 source: devnote
1010 area: site
11-moves: 2026-11-08T04:02:20Z inbox doing drag
11+moves: 2026-11-08T04:02:20Z inbox doing drag; 2026-11-08T04:20:55Z doing review agent
1212 ---
1313
1414 ## Context
@@ -22,3 +22,13 @@ Filed from `http://192.168.122.10:8080/projects/mini-coder/blob/src/cli.ts/`, on
2222 - 2026-11-08 03:49Z (agent): Triage: type feature (it was bug: the browser works, this adds navigation), priority p2, area site. No typos to fix. Builds on 1008, the read-only file browser (internal/site/templates/browse.html), which today shows one file or folder per page, with a breadcrumb.
2323
2424 Questions, since they change how it looks: (1) What does the sidebar show: the whole repo tree with folders you can expand, or only the current folder and its parents? (2) On a phone, is it hidden behind a toggle, or stacked above the file?
25+
26+- 2026-11-08 04:20Z (agent): Done, with my choices as you asked: on wide screens (lg, 1024px and up), file and folder pages get a sticky sidebar on the left. It shows the repo root with every folder on the way to the current page opened (▾), other folders closed (▸), and the current file or folder in bold accent. Every line links. On phones it is hidden, and the breadcrumb stays.
27+
28+ - internal/site/sidebar.go (new): children() lists every folder's entries once per project (also reused for the folder pages, which used to call entries() per folder); sidebar() walks down the path to the page.
29+ - browse.go: BrowsePage.Side. browse.html: a two-column grid, the sidebar scrolls on its own when long.
30+ - sidebar_test.go: which folders open, depth, and the marked page.
31+
32+ CHECKED: go vet, go test pass. Rebuilt. agent-browser on mini-coder/blob/src/cli.ts: sidebar shows bin/, src/ opened with tools/, tui/ and its files, cli.ts marked. Clicking tools/ in the sidebar opened /tree/src/tools/ with tools/ marked. Size: about 2.2 KB of a 15 KB page (Zoea-Nova README).
33+
34+ NOT CHECKED: phone width (hidden by class only), dark theme. The project's landing page has no sidebar; it has the file list already. A real tree with expand/collapse on click was left out: each page lists only its own path, so pages stay small.