diff --git a/.gitignore b/.gitignore index 883a7df..8a5e965 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /bin/ /out/ /config.json +/.data/ diff --git a/AGENTS.md b/AGENTS.md index c4c2305..65281d9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,7 +2,7 @@ Read `docs/spec.md` (requirements, security rules, build order) and `docs/decisions.md` (where the build differs from the spec) before changing -anything. +anything. For styling, read `docs/theme.md`: the look follows danieldaum.net (saturn). - Never commit, push, tag or sign. The owner reviews and commits by hand (commits are signed with biometric SSH). Leave changes in the working tree. diff --git a/README.md b/README.md index 6ee8a38..cfd0349 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ docs/ spec and design decisions - [docs/spec.md](docs/spec.md): what this is and isn't, the security rules and the build order. - [docs/decisions.md](docs/decisions.md): choices made while building. +- [docs/theme.md](docs/theme.md): how the look follows danieldaum.net. ## Licences diff --git a/cmd/daumdev/main.go b/cmd/daumdev/main.go index fac9b1c..a989457 100644 --- a/cmd/daumdev/main.go +++ b/cmd/daumdev/main.go @@ -18,6 +18,7 @@ func main() { cfgPath := flag.String("config", "/config.json", "path to config.json") once := flag.Bool("once", false, "render the site once into -out and exit") out := flag.String("out", "", "output directory for -once (must not exist)") + data := flag.String("data", "/data", "data directory (git mirrors, site builds)") flag.Parse() cfg, err := config.Load(*cfgPath) @@ -36,7 +37,7 @@ func main() { if err := os.Mkdir(*out, 0o755); err != nil { fatal(err) } - if err := build.New(cfg).Render(ctx, *out); err != nil { + if err := build.New(cfg, *data).Render(ctx, *out); err != nil { fatal(err) } } diff --git a/docs/decisions.md b/docs/decisions.md index 6c91586..ac0ddee 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -9,7 +9,8 @@ The heatmap API leaked private activity before Gitea 28.3.0, and the server runs 28.2.x. The builder counts commits on the default branch of the allowlisted repos from the local mirrors instead. Private activity can't leak whatever Gitea version runs, but only commits are counted (no PRs, issues and -so on). +so on). All authors are counted, since the anonymous API hides the user's +email, so merged commits from others show up too. ## Packages are filtered by the allowlist @@ -46,6 +47,17 @@ served with their real types. SVG and everything else is served as - Config rejects repo names that clash with routes (`static`, `v2`, `healthz`, `api`, `user`). - Dates are bucketed in UTC. -- Fonts: Geist Pixel Square from the `geist` npm package (OFL). Body text uses - system fonts. +- README links resolve to `blob/` pages, or to `tree/` pages when they end in + `/`. Images that aren't relative or https are dropped and their alt text + kept. Goldmark blanks dangerous link schemes such as `javascript:`. +- The go-import meta is added when the repo root has a `go.mod`. +- The clone box shows only the HTTPS URL for now. Tangled and GitHub links + need per-repo config, because not every repo is mirrored there. - Tooling: Go is pinned in `mise.toml`, and commands live in the `justfile`. + +## Theme follows danieldaum.net (saturn) + +The site's look matches saturn instead of a generic Flexoki light/dark theme. +It is dark only and uses saturn's tokens, palettes, fonts and components. The +details are in `docs/theme.md`. This replaces the spec's original +"light and dark via `prefers-color-scheme`". diff --git a/docs/spec.md b/docs/spec.md index 71562a5..2512a40 100644 --- a/docs/spec.md +++ b/docs/spec.md @@ -13,7 +13,8 @@ or reach Gitea's UI or API. commit log, commit diffs, releases, pull requests (read-only), packages. - Public clone: `git clone https://daum.dev/.git` - Public image pull: `docker pull daum.dev/daniel/:` -- No JavaScript. Light and dark via `prefers-color-scheme`. Flexoki palette, Geist Pixel for headings. +- No JavaScript. Matches danieldaum.net (saturn): dark only, saturn's Flexoki-based + palettes (moss by default), Geist Pixel for all text, Geist Mono for code. See `docs/theme.md`. ## Non-goals @@ -164,7 +165,7 @@ internal/build/ build loop, change detection, atomic swap internal/render/ templates, markdown, highlight, heatmap SVG internal/server/ router, static files, git + registry proxy, headers web/templates/*.html embedded -web/static/style.css embedded, Flexoki variables +web/static/style.css embedded, saturn tokens + components Dockerfile multi-stage: golang → alpine + git, non-root compose.yaml one service, example for deployment testdata/ sample Gitea JSON + a tiny test repo diff --git a/docs/theme.md b/docs/theme.md new file mode 100644 index 0000000..3badaaf --- /dev/null +++ b/docs/theme.md @@ -0,0 +1,85 @@ +# Theme + +daum.dev should look like part of danieldaum.net (the `saturn` repo). Saturn +is the source of truth. This site copies its tokens and components and adds +only what a code browser needs on top. + +## What carries over from saturn + +- **Dark only.** `color-scheme: dark`, no light mode, no `prefers-color-scheme` + switch. +- **Tokens** are copied as-is: `--background-dark`, `--surface`, `--borders`, + `--text-headings`, `--text-body`, `--text-secondary`, `--accent`, + `--accent-muted`, and the `--syn-*` syntax roles. +- **Palettes:** moss (default), ink, wine, plum, teal and flexoki, each under + `[data-theme="…"]`. Saturn picks one per visit with `theme.js`. There's no + JS here, so the build sets `data-theme` on `` from config (see + Palette choice below). +- **Fonts:** Geist Pixel Square for all text, and Geist Mono (regular and + italic) for `pre code` only, because pixel type is proportional and code + columns would drift. The woff2 files and OFL licence go in + `web/static/fonts/`. +- **Base:** Josh Comeau reset, 78ch body width, the heading scale, text links + underlined in `--accent-muted` that turn `--accent` on hover, and the focus + ring, high-contrast and reduced-motion rules. +- **Chrome:** `.site-header` with `.site-name` (daum.dev) and a nav, and a + footer nav that starts with `//` and holds links to danieldaum.net, Tangled, + GitHub and Bluesky. UI labels are lowercase like saturn's. + +## Saturn components → daum.dev pages + +| Saturn component | Used for | +| ------------------------------------- | ------------------------------------------------------ | +| `.page-header`, `.page-header--home` | profile hero (name in accent), repo header | +| `.meta`, `.meta-split`, `.meta-sep` | repo meta line, latest commit, file size and line count | +| `.pills` / `.pill` | topics, "archived", release tag, PR state | +| `.card-grid` / `.card` | repo list on the profile | +| `.section-label` | section headings: "repositories", "readme", "files" | +| `.breadcrumb` | `repo / dir / file` on tree and blob pages | +| `.table` / `.table-row` | file tree, pulls, packages | +| `.commit-log` (+ `-row`, `-hash`, `-msg`, `-date`) | latest commit box, the log page | +| `.version-list` / `.version-meta` | releases page | +| `.code-block` + `.code-label` | file viewer (label: path · size · lines), diff hunks | +| `.hl-*` classes | syntax highlighting (see below) | + +New for daum.dev, built from the same tokens: + +- **Tabs** (code · commits · releases · pulls · packages): styled like saturn's + header nav, with `aria-current` shown in `--accent`. +- **Clone box:** a read-only input on `--surface` with a `--borders` border. +- **Heatmap:** `h0` uses `--surface`. `h1`–`h4` step from `--accent-muted` to + `--accent` with `color-mix()`, so they follow the palette. +- **Language dots:** eight classes mapped to the `--syn-*` colours, so they + follow the palette too. +- **Code pages:** a wider `body.page--code` (about `min(72rem, 94vw)`), like + saturn's `page--wide`. The 78ch width is too narrow for code and diffs. +- **Line numbers:** links (`#L12`) in `--text-secondary`. The `:target` line + is highlighted with `--surface` and an `--accent-muted` edge. + +## Syntax highlighting + +Saturn highlights at build time with Shiki and emits `hl-` classes: +comment, keyword, function/link, builtin/escape, type/self/changed, +variable/heading/removed, constant, string/added and punct. Here chroma does +the tokenising, and a small Go formatter maps chroma token types to the same +`hl-*` roles. Saturn's CSS then applies unchanged, every palette's `--syn-*` +colours work, and there are no inline styles, so the CSP holds. Diffs use +`hl-added`, `hl-removed` and `hl-changed`. README code blocks go through the +same formatter. + +## Keeping in sync + +`web/static/style.css` holds two sections. The first is copied from saturn's +`global.css` (only the parts used) and marked with its source. The second is +daum.dev-only. When saturn's tokens or components change, re-copy the first +section and leave the second alone. + +## Palette choice + +Saturn's no-JS default is moss. Options here, all JS-free: + +1. Moss everywhere (`"theme": "moss"` in config). +2. Config sets a site default, and each repo may pick its own. +3. Each repo gets a palette from a hash of its name. + +Not decided yet; until then, moss everywhere. diff --git a/go.mod b/go.mod index 8dfe4a0..e074775 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module daum.dev/showcase go 1.27.4 + +require github.com/yuin/goldmark v1.8.7 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..323ce3d --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/yuin/goldmark v1.8.7 h1:XT/tNqCIbabh0ln675w4x3dv04kQBKi8NwYqi9IJaxI= +github.com/yuin/goldmark v1.8.7/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg= diff --git a/internal/build/build.go b/internal/build/build.go index 976e7a8..e78a615 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -19,14 +19,16 @@ import ( type Builder struct { Cfg *config.Config Gitea *gitea.Client + Data string // holds mirrors/ (and later site/) Now func() time.Time Log *slog.Logger } -func New(cfg *config.Config) *Builder { +func New(cfg *config.Config, data string) *Builder { return &Builder{ Cfg: cfg, Gitea: gitea.New(cfg.GiteaURL, cfg.User), + Data: data, Now: time.Now, Log: slog.Default(), } @@ -45,7 +47,7 @@ type Profile struct { // Render writes a complete site into dir, which must be empty. func (b *Builder) Render(ctx context.Context, dir string) error { - r, err := render.New(b.Now()) + rd, err := render.New(b.Now()) if err != nil { return err } @@ -68,24 +70,37 @@ func (b *Builder) Render(ctx context.Context, dir string) error { p.Avatar = name } + var repos []*repo + days, since := map[string]int{}, b.Now().AddDate(-1, 0, -7) for _, name := range b.Cfg.Repos { - repo, err := b.Gitea.Repo(ctx, name) + r, err := b.loadRepo(ctx, name) if err != nil { b.Log.Warn("skipping repo", "repo", name, "err", err) continue } - p.Repos = append(p.Repos, repo) + if r.Head != "" { + if err := r.Git.CommitDays(ctx, r.Head, since, days); err != nil { + return fmt.Errorf("%s: %w", name, err) + } + } + repos = append(repos, r) + p.Repos = append(p.Repos, r.Repo) } slices.SortStableFunc(p.Repos, func(a, c *gitea.Repo) int { return c.UpdatedAt.Compare(a.UpdatedAt) }) - p.Heatmap, p.Total = render.Heatmap(map[string]int{}, b.Now()) // filled from git in a later step + p.Heatmap, p.Total = render.Heatmap(days, b.Now()) title := user.FullName if title == "" { title = user.Login } - if err := r.Write(dir, "index.html", "profile", render.Page{Title: title, D: p}); err != nil { + if err := rd.Write(dir, "index.html", "profile", render.Page{Title: title, D: p}); err != nil { return fmt.Errorf("profile: %w", err) } + for _, rp := range repos { + if err := b.renderRepo(ctx, rd, dir, rp); err != nil { + return fmt.Errorf("%s: %w", rp.Name, err) + } + } return nil } diff --git a/internal/build/build_test.go b/internal/build/build_test.go index 1afccc2..fda50b4 100644 --- a/internal/build/build_test.go +++ b/internal/build/build_test.go @@ -9,8 +9,10 @@ import ( "io" "log/slog" "net/http" + "net/http/cgi" "net/http/httptest" "os" + "os/exec" "path/filepath" "strings" "testing" @@ -20,16 +22,69 @@ import ( "daum.dev/showcase/internal/gitea" ) -var update = flag.Bool("update", false, "rewrite golden files") +var ( + update = flag.Bool("update", false, "rewrite golden files") + keep = flag.String("keep", "", "also render the fixture site into this directory") +) + +// gitEnv isolates fixture commits from the user's git config (no signing). +var gitEnv = []string{ + "GIT_CONFIG_GLOBAL=/dev/null", "GIT_CONFIG_NOSYSTEM=1", + "GIT_AUTHOR_NAME=Daniel", "GIT_AUTHOR_EMAIL=d@example.com", + "GIT_COMMITTER_NAME=Daniel", "GIT_COMMITTER_EMAIL=d@example.com", +} -// fakeGitea serves testdata/gitea/.json and a generated avatar. It -// fails the test if a request carries credentials. +func run(t *testing.T, dir, date string, args ...string) { + t.Helper() + cmd := exec.Command("git", args...) + cmd.Dir = dir + cmd.Env = append(os.Environ(), gitEnv...) + cmd.Env = append(cmd.Env, "GIT_AUTHOR_DATE="+date, "GIT_COMMITTER_DATE="+date) + if out, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("git %v: %v\n%s", args, err, out) + } +} + +// fixtureRepos creates bare repos under root/daniel: repo-a from +// testdata/repo-a in two commits with fixed dates, and an empty repo-b. +func fixtureRepos(t *testing.T) string { + root := t.TempDir() + work := filepath.Join(root, "work") + if err := os.CopyFS(work, os.DirFS("../../testdata/repo-a")); err != nil { + t.Fatal(err) + } + run(t, work, "", "init", "-q", "-b", "main") + run(t, work, "", "add", "-A", ":!CHANGELOG.md") + run(t, work, "2026-06-01T10:00:00Z", "commit", "-q", "--no-gpg-sign", "-m", "Initial commit") + os.WriteFile(filepath.Join(work, "CHANGELOG.md"), []byte("# Changes\n"), 0o644) + run(t, work, "", "add", "CHANGELOG.md") + run(t, work, "2026-11-19T08:30:00Z", "commit", "-q", "--no-gpg-sign", "-m", "Add changelog", "-m", "With a body.") + run(t, root, "", "clone", "-q", "--bare", work, "daniel/repo-a.git") + run(t, root, "", "init", "-q", "--bare", "-b", "main", "daniel/repo-b.git") + return root +} + +// fakeGitea serves testdata/gitea/.json, a generated avatar and the +// fixture repos over smart HTTP. It fails the test if a request carries +// credentials. func fakeGitea(t *testing.T) *httptest.Server { t.Helper() + gitBackend := &cgi.Handler{ + Path: "git", + Args: []string{"http-backend"}, + Env: append([]string{"GIT_PROJECT_ROOT=" + fixtureRepos(t), "GIT_HTTP_EXPORT_ALL=1"}, gitEnv...), + } + if p, err := exec.LookPath("git"); err == nil { + gitBackend.Path = p + } srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Header.Get("Authorization") != "" || r.Header.Get("Cookie") != "" { t.Errorf("request to %s carried credentials", r.URL) } + if strings.Contains(r.URL.Path, ".git/") { + gitBackend.ServeHTTP(w, r) + return + } if strings.HasPrefix(r.URL.Path, "/avatars/") { var buf bytes.Buffer png.Encode(&buf, image.NewGray(image.Rect(0, 0, 2, 2))) @@ -66,22 +121,23 @@ func testBuilder(t *testing.T) *Builder { return &Builder{ Cfg: cfg, Gitea: gitea.New(srv.URL, cfg.User), + Data: t.TempDir(), Now: func() time.Time { return now }, Log: slog.New(slog.NewTextHandler(io.Discard, nil)), } } -func TestProfileGolden(t *testing.T) { - dir := t.TempDir() - if err := testBuilder(t).Render(context.Background(), dir); err != nil { - t.Fatal(err) - } - got, err := os.ReadFile(filepath.Join(dir, "index.html")) +func checkGolden(t *testing.T, dir, rel string) []byte { + t.Helper() + got, err := os.ReadFile(filepath.Join(dir, rel)) if err != nil { t.Fatal(err) } - golden := "../../testdata/golden/index.html" + golden := filepath.Join("../../testdata/golden", rel) if *update { + if err := os.MkdirAll(filepath.Dir(golden), 0o755); err != nil { + t.Fatal(err) + } if err := os.WriteFile(golden, got, 0o644); err != nil { t.Fatal(err) } @@ -91,17 +147,37 @@ func TestProfileGolden(t *testing.T) { t.Fatal(err) } if !bytes.Equal(got, want) { - t.Errorf("index.html differs from %s; run with -update and review the diff", golden) + t.Errorf("%s differs from %s; run `just golden` and review the diff", rel, golden) } - - for _, bad := range []string{"leaky", "should never render", " + +[bad link](javascript:alert(1)) + +## Usage + +```sh +go run ./cmd/hello +``` diff --git a/testdata/repo-a/cmd/hello/main.go b/testdata/repo-a/cmd/hello/main.go new file mode 100644 index 0000000..99974d9 --- /dev/null +++ b/testdata/repo-a/cmd/hello/main.go @@ -0,0 +1,5 @@ +package main + +import "fmt" + +func main() { fmt.Println("hello") } diff --git a/testdata/repo-a/docs/guide.md b/testdata/repo-a/docs/guide.md new file mode 100644 index 0000000..f49e5b9 --- /dev/null +++ b/testdata/repo-a/docs/guide.md @@ -0,0 +1,3 @@ +# Guide + +Nothing to see here. diff --git a/testdata/repo-a/docs/logo.png b/testdata/repo-a/docs/logo.png new file mode 100644 index 0000000..0dd1608 --- /dev/null +++ b/testdata/repo-a/docs/logo.png @@ -0,0 +1,2 @@ +�PNG + diff --git a/testdata/repo-a/go.mod b/testdata/repo-a/go.mod new file mode 100644 index 0000000..9d280fb --- /dev/null +++ b/testdata/repo-a/go.mod @@ -0,0 +1,3 @@ +module daum.dev/repo-a + +go 1.27 diff --git a/web/static/style.css b/web/static/style.css index f004f0b..cde57de 100644 --- a/web/static/style.css +++ b/web/static/style.css @@ -97,3 +97,44 @@ header.site a { color: var(--tx); } @media (max-width: 40rem) { .profile { flex-direction: column; } } + +/* repo pages */ +.repohead h1 a { color: var(--tx); } +.repohead .desc { color: var(--tx-2); margin: .5rem 0; } +.badge { font: .75rem system-ui, sans-serif; border: 1px solid var(--ui-3); border-radius: 1rem; padding: .1rem .5rem; color: var(--tx-2); vertical-align: middle; } +.topics { list-style: none; padding: 0; margin: .5rem 0; display: flex; flex-wrap: wrap; gap: .35rem; } +.topics li { font-size: .8rem; color: var(--cyan); background: var(--bg-2); border: 1px solid var(--ui); border-radius: 1rem; padding: .05rem .6rem; } + +.tabs { display: flex; flex-wrap: wrap; gap: .25rem; border-bottom: 1px solid var(--ui); margin: 1.25rem 0 1rem; } +.tabs a { color: var(--tx-2); padding: .5rem .75rem; border-bottom: 2px solid transparent; margin-bottom: -1px; } +.tabs a:hover { color: var(--tx); text-decoration: none; } +.tabs a[aria-current] { color: var(--tx); border-bottom-color: var(--orange); } + +.clone { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; } +.clone label { font-size: .85rem; color: var(--tx-2); } +.clone input { flex: 1; font: .875rem ui-monospace, "SF Mono", Menlo, monospace; padding: .4rem .6rem; color: var(--tx); background: var(--bg-2); border: 1px solid var(--ui-2); border-radius: 6px; } + +.latest { display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: baseline; padding: .6rem .75rem; background: var(--bg-2); border: 1px solid var(--ui); border-bottom: 0; border-radius: 6px 6px 0 0; font-size: .9rem; } +.latest .subject { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.sha { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .85rem; } + +.tree { width: 100%; border-collapse: collapse; border: 1px solid var(--ui); font-size: .9rem; } +.latest + .tree { border-radius: 0 0 6px 6px; } +.tree td { padding: .4rem .75rem; border-top: 1px solid var(--ui); } +.tree .name { white-space: nowrap; } +.tree .name.tree a::before { content: "▸ "; color: var(--tx-3); } +.tree .msg { color: var(--tx-2); width: 100%; max-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.tree .age { color: var(--tx-2); white-space: nowrap; text-align: right; } +.empty { color: var(--tx-2); } + +.readme { margin-top: 1.5rem; border: 1px solid var(--ui); border-radius: 6px; padding: 1rem 1.5rem; } +.markdown img { max-width: 100%; } +.markdown pre { background: var(--bg-2); padding: .75rem 1rem; border-radius: 6px; overflow-x: auto; } +.markdown :not(pre) > code { background: var(--bg-2); padding: .1em .35em; border-radius: 4px; } +.markdown table { border-collapse: collapse; } +.markdown th, .markdown td { border: 1px solid var(--ui-2); padding: .3rem .6rem; } +.markdown blockquote { margin: 0; padding-left: 1rem; border-left: 3px solid var(--ui-3); color: var(--tx-2); } + +@media (max-width: 40rem) { + .tree .msg { display: none; } +} diff --git a/web/templates/_repo.html b/web/templates/_repo.html new file mode 100644 index 0000000..a0f895e --- /dev/null +++ b/web/templates/_repo.html @@ -0,0 +1,40 @@ +{{define "repohead" -}} +
+

{{.Repo.Name}}{{if .Repo.Archived}} archived{{end}}

+ {{- with .Repo.Description}}

{{.}}

{{end}} + {{- with .Repo.Website}}

{{.}}

{{end}} + {{- with .Repo.Topics}} +
    {{range .}}
  • {{.}}
  • {{end}}
+ {{- end}} +
+ +{{- end}} + +{{define "latest" -}} +{{- $repo := .Repo.Name}}{{with .Latest}} +
+ {{.Short}} + {{.Subject}} + {{.Author}} · +
+{{- end}} +{{- end}} + +{{define "tree" -}} + + {{- range .}} + + + + + + {{- end}} +
{{if .Href}}{{.Name}}{{else}}{{.Name}}{{end}}{{.Last.Subject}}{{ago .Last.When}}
+{{- end}} diff --git a/web/templates/profile.html b/web/templates/profile.html index 909b165..2094065 100644 --- a/web/templates/profile.html +++ b/web/templates/profile.html @@ -15,7 +15,7 @@
-

{{.Total}} contributions in the last year

+

{{.Total}} commits in the last year

{{.Heatmap}}
diff --git a/web/templates/repo.html b/web/templates/repo.html new file mode 100644 index 0000000..3dd117d --- /dev/null +++ b/web/templates/repo.html @@ -0,0 +1,16 @@ +{{define "content" -}} +{{template "repohead" .}} +
+ + +
+{{- if .Latest}} +{{template "latest" .}} +{{template "tree" .Rows}} +{{- else}} +

This repository is empty.

+{{- end}} +{{- with .Readme}} +
{{.}}
+{{- end}} +{{- end}} diff --git a/web/web.go b/web/web.go index 217fe01..aad0fb9 100644 --- a/web/web.go +++ b/web/web.go @@ -3,5 +3,5 @@ package web import "embed" -//go:embed templates static +//go:embed templates/*.html static var FS embed.FS