From 317d72277bb2d3ecad5c8105fba289352dba202c Mon Sep 17 00:00:00 2001 From: daniel daum Date: Sat, 21 Nov 2026 20:19:03 -0800 Subject: [PATCH] feat: updated profile freshness indicators --- docs/decisions.md | 48 ++- internal/build/activity.go | 9 +- internal/build/build.go | 2 +- internal/build/build_test.go | 4 +- internal/build/log.go | 38 +++ internal/build/loop.go | 22 +- internal/build/repo.go | 8 + internal/gitx/gitx.go | 31 ++ internal/render/render.go | 2 + testdata/golden/index.html | 32 +- testdata/golden/repo-a/blob/README.md.html | 15 +- testdata/golden/repo-a/blob/big.txt.html | 15 +- .../golden/repo-a/blob/cmd/hello/main.go.html | 15 +- testdata/golden/repo-a/blob/data.bin.html | 15 +- .../golden/repo-a/blob/docs/logo.png.html | 15 +- testdata/golden/repo-a/branches/index.html | 27 +- testdata/golden/repo-a/commit-latest.html | 19 +- testdata/golden/repo-a/index.html | 48 +-- testdata/golden/repo-a/log/index.html | 249 ++++++++++++---- testdata/golden/repo-a/packages/index.html | 27 +- testdata/golden/repo-a/pulls/index.html | 15 +- testdata/golden/repo-a/releases/index.html | 17 +- testdata/golden/repo-a/tags/index.html | 21 +- .../golden/repo-a/tree/cmd/hello/index.html | 21 +- testdata/golden/repo-a/tree/docs/index.html | 15 +- testdata/golden/repo-b/index.html | 14 +- testdata/golden/repo-b/log/index.html | 11 +- testdata/golden/repo-b/releases/index.html | 11 +- testdata/golden/repos/index.html | 8 +- web/static/style.css | 275 ++++++++++++++++-- web/templates/_cards.html | 4 +- web/templates/_repo.html | 29 +- web/templates/log.html | 16 +- web/templates/notfound.html | 7 +- web/templates/packages.html | 2 +- web/templates/pulls.html | 2 +- web/templates/refs.html | 2 +- web/templates/releases.html | 3 +- web/templates/repo.html | 13 +- 39 files changed, 874 insertions(+), 253 deletions(-) diff --git a/docs/decisions.md b/docs/decisions.md index 1754867..8eb311d 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -419,8 +419,8 @@ are in the data, so nothing else can appear. config (in order, each must be in `repos`), or the six most recently updated. "All N repositories →" links to `/repos/`, a new top-level page that lists every allowlisted repo. The server has one extra route for it, - and `repos` is now a reserved repo name. A repo with a commit in the last - week gets an accent "active" pill and an accent edge. Cards also carry + and `repos` is now a reserved repo name. A repo with commits in the last + week gets a "N commits this week" pill and an accent edge (see Phase 5). Cards also carry the 12-week sparkline and the latest release tag. - **Activity feed:** a text timeline, modelled on Tangled's and styled after the comment threads on danieldaum.net: no boxes, a dashed rule @@ -446,3 +446,47 @@ are in the data, so nothing else can appear. - The repo-a fixture gains 25 dated commits across five months (on `docs/notes.md`, four of them on one day), repo `created_at` dates, and a merged pull (#5), so the goldens and `just demo` show a real shape. + +### Phase 5: more life on every page + +No JS was added for any of it. + +- **Freshness:** a still green dot marks a commit in the last 24 hours: + on the "updated" pill in the repo header and on tree rows. A pulsing + version was tried and dropped, since motion doesn't fit the static look. + Repo cards with commits in the last 7 days show a plain "N commits this + week" pill and an accent edge. An earlier "active"/"live" label said too + little. Releases and commits under 7 days old get an accent "new" badge. + The warm age colours stay, and they are mixes of `--syn-constant` and + `--text-secondary`, both well over 4.5:1 on boxes and hovers. +- **Repo header:** stats are compact pills on every repo page: the latest + release (an accent badge), commits, branches, tags, "updated … ago" in its + freshness colour (or the live dot), and the CI result of HEAD linked to + its checks. The code box no longer repeats branches, tags and commits. + Its top bar keeps the branch chip and the clone menu. Website, licence + and packages stay on the meta line, which is left out when empty. +- **Reuse key:** pages reused across builds (tree, blob, commit) show the + header too, so the reuse key now includes the CI status and the newest + commit's age bucket (days for the first week, then weeks, months, + years). Those pages are rebuilt when the pill's text or the live dot + would change. Within the first day the hours can lag on reused pages; the + repo home and log are rebuilt every time. +- **Commit log:** commits are grouped by day (UTC) under sticky headers + ("Today", "Yesterday", "Nov 14", with the year when it differs), one box + per day. Each row has a coloured `+N −M` from one `git log --shortstat + --diff-merges=first-parent` pass, matching the commit pages. +- **Hover and focus:** cards lift onto a lighter background with an accent + edge, and asset rows highlight like other rows. Focus rings inside boxes + sit inside the edge so they aren't clipped. The ring itself is the shared + `--accent-bright` one from Phase 1. +- **Empty states** (no releases, pulls, packages or commits, an empty repo, + no branches or tags) have a round icon, one line and a muted hint. +- **Motion:** hover transitions are 120–180 ms, and the clone menu chevron + rotates. Saturn's reduced-motion rule turns all of it off. +- **404:** the pixel "404" in `--accent-bright`, links to the featured + repos, and buttons back home and to all repositories. +- **Clone menu:** the code box no longer clips the menu (`overflow: + visible`). Its first child and last file row take the rounded corners + instead. +- The fixture's newest commit moves to the morning of the fixed build day, + so the goldens and `just demo` show live dots, "Today" and "new". diff --git a/internal/build/activity.go b/internal/build/activity.go index da67d36..c20d05b 100644 --- a/internal/build/activity.go +++ b/internal/build/activity.go @@ -27,7 +27,7 @@ type RepoCard struct { *gitea.Repo Spark template.HTML // 12-week commit sparkline Release string // latest release tag - Active bool // a commit in the last week + Week int // commits in the last 7 days } // FeedItem is one event: "push", "created", "release", "opened" or "merged". @@ -76,7 +76,12 @@ func (b *Builder) activity(p *Profile, repos []*repo, login string) { ts = append(ts, c.When) } c := RepoCard{Repo: r.Repo, Spark: render.Sparkline(render.Weeks(ts, now, sparkWeeks)), Release: r.LatestTag()} - c.Active = len(r.Recent) > 0 && now.Sub(r.Recent[0].When) < activeFor + for _, cm := range r.Year { // newest first + if now.Sub(cm.When) >= activeFor { + break + } + c.Week++ + } p.Repos = append(p.Repos, c) } slices.SortStableFunc(p.Repos, func(a, c RepoCard) int { return c.UpdatedAt.Compare(a.UpdatedAt) }) diff --git a/internal/build/build.go b/internal/build/build.go index cc4453e..e05b5b8 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -129,7 +129,7 @@ func (b *Builder) Render(ctx context.Context, dir string) error { if err := rd.Write(dir, "repos/index.html", "repos", render.Page{Title: "Repositories · " + title, D: p}); err != nil { return fmt.Errorf("repos page: %w", err) } - if err := rd.Write(dir, "404.html", "notfound", render.Page{Title: "not found"}); err != nil { + if err := rd.Write(dir, "404.html", "notfound", render.Page{Title: "not found", D: p}); err != nil { return err } for _, rp := range repos { diff --git a/internal/build/build_test.go b/internal/build/build_test.go index 43369e1..cb7a8a9 100644 --- a/internal/build/build_test.go +++ b/internal/build/build_test.go @@ -78,9 +78,9 @@ func fixtureRepos(t *testing.T) string { os.WriteFile(filepath.Join(work, "cmd/hello/main.go"), []byte("package main\n\nimport \"fmt\"\n\nfunc main() { fmt.Println(\"hello, world\") }\n"), 0o644) os.WriteFile(filepath.Join(work, "data.bin"), []byte("bin\x00ary2"), 0o644) run(t, work, "", "add", "-A") - run(t, work, "2026-11-19T08:30:00Z", "commit", "-q", "--no-gpg-sign", "-m", "Add changelog", "-m", "With a body.") + run(t, work, "2026-11-21T08:30:00Z", "commit", "-q", "--no-gpg-sign", "-m", "Add changelog", "-m", "With a body.") run(t, work, "", "tag", "v0.1.0", "HEAD~26") - run(t, work, "2026-11-19T09:00:00Z", "tag", "-a", "-m", "v0.2.0", "v0.2.0") + run(t, work, "2026-11-21T09:00:00Z", "tag", "-a", "-m", "v0.2.0", "v0.2.0") run(t, work, "", "branch", "feature/flag") run(t, root, "", "clone", "-q", "--bare", work, "daniel/repo-a.git") run(t, root, "", "init", "-q", "--bare", "-b", "main", "daniel/repo-b.git") diff --git a/internal/build/log.go b/internal/build/log.go index caa2cb7..bc8aa7f 100644 --- a/internal/build/log.go +++ b/internal/build/log.go @@ -2,6 +2,7 @@ package build import ( "context" + "time" "daum.dev/showcase/internal/gitea" @@ -13,6 +14,17 @@ type LogPage struct { Repo *repo Tab string Commits []gitx.Commit + Days []LogDay // the same commits, grouped by day (UTC) +} + +type LogDay struct { + Title string // "Today", "Yesterday", "Nov 14", "Nov 14, 2025" + Commits []LogCommit +} + +type LogCommit struct { + gitx.Commit + gitx.Stat } type CommitPage struct { @@ -34,6 +46,18 @@ func (b *Builder) renderLog(ctx context.Context, rd *render.Renderer, dir string if p.Commits, err = r.Git.Log(ctx, r.Head, b.Cfg.MaxCommits, ""); err != nil { return err } + stats, err := r.Git.ShortStats(ctx, r.Head, b.Cfg.MaxCommits) + if err != nil { + return err + } + last := "" + for _, c := range p.Commits { + if d := c.When.Format("2006-01-02"); d != last { + p.Days, last = append(p.Days, LogDay{Title: dayTitle(c.When, b.Now())}), d + } + day := &p.Days[len(p.Days)-1] + day.Commits = append(day.Commits, LogCommit{c, stats[c.Hash]}) + } } if err := rd.Write(dir, r.Name+"/log/index.html", "log", render.Page{Title: "commits · " + r.Name, Wide: true, D: &p}); err != nil { return err @@ -73,3 +97,17 @@ func (b *Builder) renderLog(ctx context.Context, rd *render.Renderer, dir string } return nil } + +// dayTitle names a day relative to now (UTC). +func dayTitle(t, now time.Time) string { + t, now = t.UTC(), now.UTC() + switch d := t.Format("2006-01-02"); { + case d == now.Format("2006-01-02"): + return "Today" + case d == now.AddDate(0, 0, -1).Format("2006-01-02"): + return "Yesterday" + case t.Year() != now.Year(): + return t.Format("Jan 2, 2006") + } + return t.Format("Jan 2") +} diff --git a/internal/build/loop.go b/internal/build/loop.go index b90ca01..e6f0446 100644 --- a/internal/build/loop.go +++ b/internal/build/loop.go @@ -114,7 +114,7 @@ func (b *Builder) prune(keep ...string) { func (b *Builder) reuse(r *repo, dir string, dirs ...string) bool { // everything the shared repo header and tabs show h, _ := json.Marshal([]any{r.Head, r.Description, r.Website, r.Topics, r.Archived, r.DefaultBranch, r.LatestTag(), - len(r.Branches), len(r.Tags), len(r.Releases), len(r.Pulls), r.PackageCount(), r.License, r.Avatar}) + len(r.Branches), len(r.Tags), len(r.Releases), len(r.Pulls), r.PackageCount(), r.License, r.Avatar, r.Status, b.ageKey(r)}) key := fmt.Sprintf("%x", sha256.Sum256(h)) if b.st.next == nil { // -once mode: no previous build return false @@ -153,3 +153,23 @@ func linkTree(src, dst string) error { return os.Link(p, target) }) } + +// ageKey buckets the age of the newest commit like the "updated … ago" pill +// shows it past the first day (days, then weeks, months, years), so reused +// pages are rebuilt when that text or the live dot would change. +func (b *Builder) ageKey(r *repo) string { + lc := r.LastCommit() + if lc == nil { + return "" + } + switch d := int(b.Now().Sub(lc.When).Hours() / 24); { + case d < 7: + return fmt.Sprintf("d%d", d) + case d < 30: + return fmt.Sprintf("w%d", d/7) + case d < 365: + return fmt.Sprintf("m%d", d/30) + default: + return fmt.Sprintf("y%d", d/365) + } +} diff --git a/internal/build/repo.go b/internal/build/repo.go index 4b56a55..f4857c3 100644 --- a/internal/build/repo.go +++ b/internal/build/repo.go @@ -75,6 +75,14 @@ func (r *repo) CommitHref(hash string) string { return "/" + r.Name + "/commit/" + hash + "/" } +// LastCommit is the newest commit on the default branch, nil if none. +func (r *repo) LastCommit() *gitx.Commit { + if len(r.Recent) == 0 { + return nil + } + return &r.Recent[0] +} + // PackageCount counts what the packages page lists: registry images plus // non-container packages from the API. func (r *repo) PackageCount() int { diff --git a/internal/gitx/gitx.go b/internal/gitx/gitx.go index 2dad98d..0a36d2e 100644 --- a/internal/gitx/gitx.go +++ b/internal/gitx/gitx.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "path" + "regexp" "strconv" "strings" "time" @@ -190,6 +191,36 @@ func (r Repo) LastChanges(ctx context.Context, rev string) (map[string]Commit, e return last, nil } +// Stat is a commit's line counts against its first parent. +type Stat struct{ Added, Deleted int } + +var ( + insRe = regexp.MustCompile(`(\d+) insertion`) + delRe = regexp.MustCompile(`(\d+) deletion`) +) + +// ShortStats returns line counts for the newest n commits on rev, measured +// against the first parent like the commit pages. +func (r Repo) ShortStats(ctx context.Context, rev string, n int) (map[string]Stat, error) { + out, err := r.run(ctx, "log", "-n", strconv.Itoa(n), "--format=%x1e%H", "--shortstat", "--diff-merges=first-parent", "--end-of-options", rev) + if err != nil { + return nil, err + } + stats := map[string]Stat{} + for _, rec := range strings.Split(string(out), "\x1e")[1:] { + hash, rest, _ := strings.Cut(rec, "\n") + var s Stat + if m := insRe.FindStringSubmatch(rest); m != nil { + s.Added, _ = strconv.Atoi(m[1]) + } + if m := delRe.FindStringSubmatch(rest); m != nil { + s.Deleted, _ = strconv.Atoi(m[1]) + } + stats[strings.TrimSpace(hash)] = s + } + return stats, nil +} + // CommitsSince returns the commits on rev since a time, newest first, with // hash, author, time (UTC) and subject only. func (r Repo) CommitsSince(ctx context.Context, rev string, since time.Time) ([]Commit, error) { diff --git a/internal/render/render.go b/internal/render/render.go index dd2a1fe..e66d8d5 100644 --- a/internal/render/render.go +++ b/internal/render/render.go @@ -57,6 +57,8 @@ func New(now time.Time) (*Renderer, error) { funcs := template.FuncMap{ "ago": r.ago, "fresh": r.fresh, + "live": func(t time.Time) bool { return !t.IsZero() && r.Now.Sub(t) < 24*time.Hour }, + "isnew": func(t time.Time) bool { return !t.IsZero() && r.Now.Sub(t) < 7*24*time.Hour }, "ficon": fileIcon, "dec": func(i int) int { return i - 1 }, "dict": func(kv ...any) map[string]any { diff --git a/testdata/golden/index.html b/testdata/golden/index.html index b3f0d9a..c28bf84 100644 --- a/testdata/golden/index.html +++ b/testdata/golden/index.html @@ -5,12 +5,12 @@ Daniel Daum - - + + - + -

No commits yet.

+
+ +

No commits yet.

Nothing has been pushed to the default branch.

+