xonecas.io
8356
Wx

www-xonecas-io / commit 66b31ca

builds remove pages, clones and activity pages of projects no longer shown (1023)

Co-Authored-By: Claude Opus 5.5

Sean Caetano Martin2026-11-08 66b31caa9e686773fdd8c35f3e4ac0759ff0593f parent e503210

5 files changed

internal/site/activity.go+4−0
@@ -1,6 +1,7 @@
11 package site
22
33 import (
4+ "os"
45 "path/filepath"
56 "slices"
67 "strconv"
@@ -37,6 +38,9 @@ const perPage = 100
3738 // writeActivity writes /activity/<year>/ and /activity/<year>/<page>/ for every year from the first to the last commit,
3839 // and /activity/ as the latest year's first page. feed is my commits across the shown projects.
3940 func writeActivity(out string, shown []project.Project, feed []Commit) error {
41+ if err := os.RemoveAll(filepath.Join(out, "activity")); err != nil { // years and pages that no longer exist go too
42+ return err
43+ }
4044 all, years := map[string]int{}, map[string]int{}
4145 first, last := "9999", "0000"
4246 for _, p := range shown {
internal/site/build.go+1−1
@@ -98,7 +98,7 @@ func Build(projects []project.Project, out, tailwind string) error {
9898 return err
9999 }
100100 }
101- return nil
101+ return prune(out, shown)
102102 }
103103
104104 // readStamp hashes this program, which holds every template, with the asset versions, and says whether out was built by them.
internal/site/build_test.go+9−0
@@ -37,9 +37,18 @@ func TestBuild(t *testing.T) {
3737 {Name: "a-fork", Info: project.Info{Hidden: "fork"}},
3838 }
3939 out := t.TempDir()
40+ for _, stale := range []string{"projects/a-fork/index.html", "a-fork.git/HEAD", "activity/1999/index.html"} {
41+ os.MkdirAll(filepath.Join(out, filepath.Dir(stale)), 0o755)
42+ os.WriteFile(filepath.Join(out, stale), nil, 0o644)
43+ }
4044 if err := Build(projects, out, ""); err != nil {
4145 t.Fatal(err)
4246 }
47+ for _, stale := range []string{"projects/a-fork", "a-fork.git", "activity/1999"} {
48+ if _, err := os.Stat(filepath.Join(out, stale)); err == nil {
49+ t.Errorf("%s is left from an earlier build", stale)
50+ }
51+ }
4352 page, err := os.ReadFile(filepath.Join(out, "index.html"))
4453 if err != nil {
4554 t.Fatal(err)
internal/site/prune.go+38−0
@@ -0,0 +1,38 @@
1+package site
2+
3+import (
4+ "os"
5+ "path/filepath"
6+ "strings"
7+
8+ "xonecas.io/site/internal/project"
9+)
10+
11+// prune removes what an earlier build wrote for projects that are no longer shown, hidden or renamed since:
12+// their pages under projects/ and their clones.
13+func prune(out string, shown []project.Project) error {
14+ keep := map[string]bool{"index.html": true}
15+ for _, p := range shown {
16+ keep[p.Name] = true
17+ }
18+ pages, err := os.ReadDir(filepath.Join(out, "projects"))
19+ if err != nil {
20+ return err
21+ }
22+ for _, e := range pages {
23+ if !keep[e.Name()] {
24+ if err := os.RemoveAll(filepath.Join(out, "projects", e.Name())); err != nil {
25+ return err
26+ }
27+ }
28+ }
29+ clones, _ := filepath.Glob(filepath.Join(out, "*.git"))
30+ for _, c := range clones {
31+ if !keep[strings.TrimSuffix(filepath.Base(c), ".git")] {
32+ if err := os.RemoveAll(c); err != nil {
33+ return err
34+ }
35+ }
36+ }
37+ return nil
38+}
tickets/1023-hidden-or-renamed-projects-stay-in-public-after.md+16−2
@@ -2,14 +2,28 @@
22 id: 1023
33 title: Hidden or renamed projects stay in public/ after a rebuild
44 type: bug
5-status: inbox
5+status: review
66 priority: p2
77 area: site
88 created: 2026-11-08T04:09:56Z
9-updated: 2026-11-08T04:09:56Z
9+updated: 2026-11-08T05:26:20Z
1010 source: agent
11+moves: 2026-11-08T05:07:41Z inbox doing drag; 2026-11-08T05:26:20Z doing review agent
1112 ---
1213
1314 Build (internal/site/build.go) writes only shown projects and never removes others. When a project becomes hidden (overrides.txt 'hide', a fork flag) or is renamed, its old public/projects/<name>/ pages, and since 1015 its public/<name>.git clone, stay in public/ and keep being served.
1415
1516 Seen in the code: the only removals are browse.go:55 (tree/ and blob/ inside a shown project) and clone.go (its own <name>.git). Not reproduced: I did not hide a project and rebuild to watch it.
17+
18+## Notes
19+
20+- 2026-11-08 05:26Z (agent): Fixed: a build now removes what earlier builds wrote for projects that are no longer shown, whether hidden or renamed. That covers public/projects/<name>/ and public/<name>.git. New internal/site/prune.go runs at the end of Build and keeps only the shown names plus projects/index.html.
21+
22+ /activity is now cleared before it's written. That also covers the leftover year and page folders I noted on 1030, for example when a year drops from 21 pages to 20.
23+
24+ Checked:
25+ - TestBuild plants projects/a-fork/, a-fork.git and activity/1999/ before building, then checks all three are gone.
26+ - With the real data I created public/projects/ghost/, public/ghost.git and public/activity/2026/99/, ran make build, and all three were removed. Left in place: 82 project folders plus index.html, and 82 clones. /activity/ and /activity/2026/21/ still serve.
27+ - go vet and go test pass.
28+
29+ Not checked: hiding a real project through overrides.txt and rebuilding. The planted folders exercise the same path.