xonecas.io
8356
Wx

www-xonecas-io / commit 649d9e6

/activity in pages of 100 commits and /projects in pages of 20, under a shared pager (1030)

Co-Authored-By: Claude Opus 5.5

Sean Caetano Martin2026-11-08 649d9e6c223ba42a5e944b7874a7023ca50e1eac parent 961bb3c

8 files changed

internal/site/activity.go+44−25
@@ -22,17 +22,20 @@ type Day struct {
2222 Commits []Commit
2323 }
2424
25-// ActivityPage is one year of my commits: the year list, its months, and its commits by day.
25+// ActivityPage is one page of a year of my commits: the year list, its months, and a page of its commits by day.
2626 type ActivityPage struct {
27- Year string
28- Total int
29- Years []YearCount
30- Months []Cell
31- Days []Day
27+ Year string
28+ Total, Page, Pages int
29+ Years []YearCount
30+ Months []Cell
31+ Days []Day
3232 }
3333
34-// writeActivity writes /activity/<year>/ for every year from the first to the last commit,
35-// and /activity/ as the latest year. feed is my commits across the shown projects.
34+// perPage is how many commits an activity page shows.
35+const perPage = 100
36+
37+// writeActivity writes /activity/<year>/ and /activity/<year>/<page>/ for every year from the first to the last commit,
38+// and /activity/ as the latest year's first page. feed is my commits across the shown projects.
3639 func writeActivity(out string, shown []project.Project, feed []Commit) error {
3740 all, years := map[string]int{}, map[string]int{}
3841 first, last := "9999", "0000"
@@ -52,28 +55,44 @@ func writeActivity(out string, shown []project.Project, feed []Commit) error {
5255 }
5356 slices.SortStableFunc(feed, func(a, b Commit) int { return strings.Compare(b.Date, a.Date) })
5457 for _, y := range list {
55- page := ActivityPage{Year: y.Year, Total: y.Count, Years: list, Months: months(y.Year, all)}
56- day := ""
58+ var mine []Commit
5759 for _, c := range feed {
58- if !strings.HasPrefix(c.Date, y.Year) {
59- continue
60- }
61- if c.Date != day {
62- t, _ := time.Parse(time.DateOnly, c.Date)
63- page.Days, day = append(page.Days, Day{Label: t.Format("Mon 2 Jan")}), c.Date
60+ if strings.HasPrefix(c.Date, y.Year) {
61+ mine = append(mine, c)
6462 }
65- c.Date = "" // the day's heading says it
66- page.Days[len(page.Days)-1].Commits = append(page.Days[len(page.Days)-1].Commits, c)
67- }
68- paths := []string{filepath.Join(out, "activity", y.Year, "index.html")}
69- if y.Year == last {
70- paths = append(paths, filepath.Join(out, "activity", "index.html"))
7163 }
72- for _, path := range paths {
73- if err := render(path, "activity.html", page); err != nil {
74- return err
64+ pages := max(1, (len(mine)+perPage-1)/perPage)
65+ for n := 1; n <= pages; n++ {
66+ page := ActivityPage{y.Year, y.Count, n, pages, list, months(y.Year, all), days(mine[(n-1)*perPage : min(n*perPage, len(mine))])}
67+ dir := filepath.Join(out, "activity", y.Year)
68+ if n > 1 {
69+ dir = filepath.Join(dir, strconv.Itoa(n))
70+ }
71+ paths := []string{filepath.Join(dir, "index.html")}
72+ if y.Year == last && n == 1 {
73+ paths = append(paths, filepath.Join(out, "activity", "index.html"))
74+ }
75+ for _, path := range paths {
76+ if err := render(path, "activity.html", page); err != nil {
77+ return err
78+ }
7579 }
7680 }
7781 }
7882 return nil
7983 }
84+
85+// days groups commits, newest first, by the day they were made.
86+func days(commits []Commit) []Day {
87+ var out []Day
88+ day := ""
89+ for _, c := range commits {
90+ if c.Date != day {
91+ t, _ := time.Parse(time.DateOnly, c.Date)
92+ out, day = append(out, Day{Label: t.Format("Mon 2 Jan")}), c.Date
93+ }
94+ c.Date = "" // the day's heading says it
95+ out[len(out)-1].Commits = append(out[len(out)-1].Commits, c)
96+ }
97+ return out
98+}
internal/site/assets/site.css+8−0
@@ -116,3 +116,11 @@
116116 .range input::-moz-range-thumb { pointer-events: auto; width: 1.25rem; height: 1.25rem; box-sizing: border-box; border: 1.5px solid var(--color-ink); border-radius: 2px; background: var(--color-accent); cursor: grab; }
117117 .range input:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--color-ink); outline-offset: 2px; }
118118 .range input:focus-visible::-moz-range-thumb { outline: 2px solid var(--color-ink); outline-offset: 2px; }
119+
120+/* Pager (pager.js): small and soft, with the current page in ink and a dead arrow faded. */
121+.pager { display: flex; flex-wrap: wrap; justify-content: center; gap: .25rem; margin-top: 2rem; font: .8rem var(--font-mono); color: var(--color-soft); }
122+.pager > * { min-width: 1.75rem; padding: .25rem .375rem; text-align: center; border-radius: 2px; color: inherit; text-decoration: none; }
123+.pager a:hover { color: var(--color-ink); background: var(--color-line); }
124+.pager [aria-current] { color: var(--color-paper); background: var(--color-ink); }
125+.pager [aria-label] { font: 1rem/1 var(--font-sans); }
126+.pager span[aria-label] { opacity: .35; }
internal/site/static/pager.js+23−0
@@ -0,0 +1,23 @@
1+// Draws a discreet pager into a nav.pager: arrows, the first and last pages, the current one and its
2+// neighbours, and dots for the gaps. href(n) is the address of page n. Static pages pass theirs in data attributes.
3+function pager(nav, page, pages, href) {
4+ const item = (n, text, label) => {
5+ const e = document.createElement(n ? "a" : "span");
6+ e.textContent = text;
7+ if (n) e.href = href(n);
8+ if (n === page) e.ariaCurrent = "page";
9+ if (label) e.ariaLabel = label;
10+ return e;
11+ };
12+ const items = [item(page > 1 && page - 1, "←", "Previous page")];
13+ for (let n = 1, last = 0; n <= pages; n++) {
14+ if (n > 1 && n < pages && Math.abs(n - page) > 1) continue;
15+ if (n - last > 1) items.push(item(0, "…"));
16+ items.push(item(n, n)), last = n;
17+ }
18+ items.push(item(page < pages && page + 1, "→", "Next page"));
19+ nav.replaceChildren(...items);
20+ nav.hidden = pages < 2;
21+}
22+for (const nav of document.querySelectorAll("nav.pager[data-pages]"))
23+ pager(nav, +nav.dataset.page, +nav.dataset.pages, n => nav.dataset.href.replace("{n}", n > 1 ? n + "/" : ""));
internal/site/static/projects.js+10−2
@@ -1,6 +1,7 @@
11 // Filters, sorts and searches the /projects list, and keeps the view in the URL.
22 // Tags from different pairs must all match; tags of the same pair match either.
33 // The date range keeps a project with any commit in a month between its two thumbs, over a bar per month of active projects.
4+// The matches show perPage at a time; the pager links reload the page with ?page=N, and any change goes back to page 1.
45 const form = document.getElementById("filters"), list = document.getElementById("rows");
56 const search = document.querySelector("input[name=q]"), rows = [...list.children];
67 const sorts = {
@@ -8,6 +9,8 @@ const sorts = {
89 oldest: (a, b) => a.dataset.first.localeCompare(b.dataset.first),
910 commits: (a, b) => b.dataset.commits - a.dataset.commits,
1011 };
12+const perPage = 20, nav = document.querySelector("nav.pager");
13+let page;
1114 const ym = (y, m) => `${y}-${String(m).padStart(2, "0")}`, months = [];
1215 const lo = rows.map(r => r.dataset.first).sort()[0], hi = rows.map(r => r.dataset.last).sort().at(-1).slice(0, 7);
1316 for (let y = +lo.slice(0, 4), m = +lo.slice(5, 7); ym(y, m) <= hi; m === 12 ? (y++, m = 1) : m++) months.push(ym(y, m));
@@ -31,6 +34,9 @@ function apply() {
3134 shown += !r.hidden;
3235 list.append(r);
3336 }
37+ const pages = Math.max(1, Math.ceil(shown / perPage)), skip = ((page = Math.min(page, pages)) - 1) * perPage;
38+ let i = 0;
39+ for (const r of rows) if (!r.hidden) r.hidden = i++ < skip || i > skip + perPage;
3440 document.getElementById("shown").textContent = shown;
3541 document.getElementById("none").hidden = shown > 0;
3642 const url = new URLSearchParams();
@@ -39,6 +45,8 @@ function apply() {
3945 if (q) url.set("q", q);
4046 if (a > 0) url.set("from", from);
4147 if (b < months.length - 1) url.set("to", to);
48+ pager(nav, page, pages, n => "?" + new URLSearchParams([...url, ...(n > 1 ? [["page", n]] : [])]));
49+ if (page > 1) url.set("page", page);
4250 history.replaceState(null, "", url.size ? "?" + url : location.pathname);
4351 }
4452
@@ -46,11 +54,11 @@ const url = new URLSearchParams(location.search), want = url.getAll("tag");
4654 for (const i of form.tag) i.checked = want.includes(i.value);
4755 form.sort.value = sorts[url.get("sort")] ? url.get("sort") : "recent";
4856 search.value = url.get("q") || "";
57+page = Math.max(1, +url.get("page") || 1);
4958 form.from.max = form.to.max = months.length - 1;
5059 form.from.value = Math.max(0, months.indexOf(url.get("from")));
5160 form.to.value = url.has("to") && months.includes(url.get("to")) ? months.indexOf(url.get("to")) : months.length - 1;
5261 search.form.addEventListener("submit", e => e.preventDefault());
53-search.addEventListener("input", apply);
54-form.addEventListener("input", apply);
62+for (const e of [search, form]) e.addEventListener("input", () => apply(page = 1));
5563 form.hidden = false;
5664 apply();
internal/site/templates/activity.html+3−1
@@ -1,4 +1,4 @@
1-{{define "activity.html"}}{{template "head" (printf "Activity %s" .Year)}}{{template "nav" "Activity"}}
1+{{define "activity.html"}}{{template "head" (printf "Activity %s%s" .Year (or (and (gt .Page 1) (printf ", page %d" .Page)) ""))}}{{template "nav" "Activity"}}
22 <main class="px-4 sm:px-8 py-6 max-w-[1440px] mx-auto grid grid-cols-1 lg:grid-cols-[17rem_minmax(0,1fr)] gap-x-10 gap-y-8">
33 <aside class="order-2 lg:order-none">
44 <h2 class="font-bold text-lg mb-2">Years</h2>
@@ -19,6 +19,8 @@
1919 <div class="flex items-baseline justify-between border-b-[1.5px] border-ink pb-1"><h2 class="font-bold">{{.Label}}</h2><span class="text-xs text-soft">{{len .Commits}} commit{{if gt (len .Commits) 1}}s{{end}}</span></div>
2020 {{range .Commits}}{{template "commit-row" .}}{{end}}
2121 </section>{{else}}<p class="mt-6 font-serif italic text-soft">No commits in {{.Year}}.</p>{{end}}
22+ <nav class="pager" aria-label="Pages" data-page="{{.Page}}" data-pages="{{.Pages}}" data-href="/activity/{{.Year}}/{n}" hidden></nav>
2223 </div>
2324 </main>
25+<script src="/pager.js"></script>
2426 {{template "foot"}}{{end}}
internal/site/templates/projects.html+2−0
@@ -18,6 +18,8 @@
1818 {{range .Rows}}<li data-name="{{lower .El.Name}}" data-tags="{{range .Tags}}{{.}} {{end}}" data-first="{{.First}}" data-last="{{.Last}}" data-months="{{.Months}}" data-commits="{{.El.Weight}}">{{template "project-row" .}}</li>{{end}}
1919 </ol>
2020 <p id="none" hidden class="py-6 text-soft">No project matches.</p>
21+ <nav class="pager" aria-label="Pages" hidden></nav>
2122 </main>
23+<script src="/pager.js"></script>
2224 <script src="/projects.js"></script>
2325 {{template "foot"}}{{end}}
tickets/1030-activity-and-projects-need-pagination.md+23−3
@@ -2,12 +2,32 @@
22 id: 1030
33 title: activity and projects need pagination
44 type: feature
5-status: doing
5+status: review
66 priority: p2
77 created: 2026-11-08T04:38:19Z
8-updated: 2026-11-08T04:38:50Z
8+updated: 2026-11-08T04:49:34Z
99 source: human
10-moves: 2026-11-08T04:38:48Z inbox doing field
10+moves: 2026-11-08T04:38:48Z inbox doing field; 2026-11-08T04:49:34Z doing review agent
11+area: site
1112 ---
1213
1314 use pagination buttons at the bottom, with arrows and dots, discreete.
15+
16+## Notes
17+
18+- 2026-11-08 04:49Z (agent): Done: /activity and /projects both end with a small pager, like ← 1 … 4 [5] 6 … 21 →. It's in mono, soft grey. The current page is in ink, a dead arrow is faded, and the dots replace runs of hidden pages. I read 'dots' as those ellipsis gaps, not carousel dots. The pager hides when there is only one page.
19+
20+ /activity is split in the build: 100 commits per page, at /activity/<year>/ then /activity/<year>/2/, 3/ and so on. /activity/ is still the latest year's first page. 2026 went from one 1.87MB page to 21 pages of about 100KB. The year list, the total and the month strip stay on every page. A day cut by a page break shows its heading again on the next page, and the count beside each heading covers only that page.
21+
22+ /projects pages in the browser: 20 matching rows a page. The 'N projects' heading still counts all matches. The links are ?page=N and keep the filters. Any change to the filters, sort or search goes back to page 1, and a page number past the end clamps to the last page.
23+
24+ Files: static/pager.js (new, shared), assets/site.css (.pager), activity.go (pages, days()), templates/activity.html and projects.html, static/projects.js.
25+
26+ Checked in agent-browser:
27+ - /activity/2026/5/: 100 rows, links 4/6/1/21 right, title 'Activity 2026, page 5'.
28+ - /activity/: page 1 of 21. 2019, an empty year, shows no pager.
29+ - /projects/?page=3: 20 of 82 rows. Ticking frontend makes it 38 matches over 2 pages and resets to page 1. ?tag=frontend&page=9 clamps to page 2 (18 rows). A search with no match hides the pager.
30+ - At 390px there's no horizontal scroll.
31+ go vet and go test pass.
32+
33+ Not checked: without JS the activity pager doesn't show, since pager.js draws it. Leftover page folders from an earlier build with more pages would stay in public/ (same cause as 1023).
tickets/attachments/1030/-activity-2026-5- pager.png+0−0
Binary file, not shown.