// Package site is the route table: the one file you edit when adding a // page or an endpoint. Modules are the "what", routes are the "where". package site import ( "gsg/internal/api" "gsg/internal/core" ) func Routes() []core.Route { return []core.Route{ // ---- site-scoped ------------------------------------------------- {Name: "index", Scope: core.ScopeSite, CacheableAnon: true, Pattern: "GET /{$}", Render: core.View{Template: "index.html"}}, {Name: "api-index", Scope: core.ScopeSite, Pattern: "GET /api/repos.json", Render: core.JSON{Build: api.IndexEndpoint}}, // ---- per repository ---------------------------------------------- // NavLabel order below is the order tabs appear in the repo-scoped // nav (top bar and page-nav chips) -- see core.BuildNav. {Name: "repo", CacheableAnon: true, Pattern: "GET /{repo}/{$}", Render: core.View{Template: "tree.html"}}, {Name: "api-repo", Pattern: "GET /{repo}/api/repo.json", Render: core.JSON{Build: api.RepoEndpoint}}, // {rest...} fuses ref and path; SplitRefPath separates them by // longest-matching ref, so feature/x/src/main.go works. {Name: "tree", NavLabel: "files", CacheableAnon: true, Pattern: "GET /{repo}/tree/{rest...}", Render: core.View{Template: "tree.html"}}, {Name: "log", NavLabel: "log", CacheableAnon: true, Pattern: "GET /{repo}/log/{rest...}", Render: core.View{Template: "log.html"}}, {Name: "blob", Pattern: "GET /{repo}/blob/{rest...}", Render: core.View{Template: "blob.html"}}, // Actual file bytes. See core.Raw for why this is not text/html. {Name: "raw", Pattern: "GET /{repo}/raw/{rest...}", Render: core.Raw{Module: "blobraw"}}, // The DAG across every ref. {rest...} carries only a ref (never a // path, there's nothing to browse into) -- it exists purely so the // selected branch survives navigating here and back out again. {Name: "graph", NavLabel: "graph", CacheableAnon: true, Pattern: "GET /{repo}/graph/{rest...}", Render: core.View{Template: "graph.html"}}, {Name: "refs", NavLabel: "refs", CacheableAnon: true, Pattern: "GET /{repo}/refs/{rest...}", Render: core.View{Template: "refs.html"}}, // Arbitrary two-commit diff: /demo/compare/main...feature. Not // CacheableAnon: a diff body is bounded only by MaxGit (16 MiB, // larger than a blob preview), and every valid ref pair is a // distinct key -- a repo with N refs has ~N^2 reachable ones. The // response cache has no size-aware eviction, so this route would // risk filling it with a few huge entries for no real hit-rate // benefit (see internal/core/route.go's CacheableAnon doc). {Name: "compare", Pattern: "GET /{repo}/compare/{range}", Render: core.View{Template: "compare.html"}}, // SHA-addressed: content can never change, so cache forever. {Name: "commit", Immutable: true, Pattern: "GET /{repo}/commit/{rev}", Render: core.View{Template: "commit.html"}}, {Name: "api-commit", Immutable: true, Pattern: "GET /{repo}/api/commit/{rev}", Render: core.JSON{Build: api.CommitEndpoint}}, } }