summaryrefslogtreecommitdiff
path: root/cgithub/src/app.ts
diff options
context:
space:
mode:
authorJoe Mou <dev@mou.fo>2026-08-11 13:32:44 -0400
committerJoe Mou <dev@mou.fo>2026-08-11 17:37:02 -0400
commit866f99c414cb3d102483ce21c68a0e62b394baaa (patch)
tree973b8e526bf51e8a05f6daab262d84035b7e2901 /cgithub/src/app.ts
parent10f923b51e2844486651493b44974e418a2be6d9 (diff)
Keep the ref picker on the current view and path
Diffstat (limited to 'cgithub/src/app.ts')
-rw-r--r--cgithub/src/app.ts12
1 files changed, 9 insertions, 3 deletions
diff --git a/cgithub/src/app.ts b/cgithub/src/app.ts
index 9a7ee8e..81e47fd 100644
--- a/cgithub/src/app.ts
+++ b/cgithub/src/app.ts
@@ -155,12 +155,18 @@ export function createApp(eta: Eta) {
// be visited directly. Keep the site's initial page loads plain server-
// rendered HTML while still surfacing data (branches/tags, latest commit)
// that would otherwise require an extra scrape on every page view.
- app.get("/api/:owner/:repo/refs/:type", async (c) => {
- const { owner, repo, type } = c.req.param();
+ // The view and path are where the picker was opened, so each ref can link to
+ // the same page on another ref.
+ app.get("/api/:owner/:repo/refs/:type/:view/:path{.*}?", async (c) => {
+ const { owner, repo, type, view, path = "" } = c.req.param();
if (type !== "branches" && type !== "tags") {
return c.notFound();
}
- return tryRenderFragment(c, "_refs.eta", getGitHubRefs(owner, repo, type));
+ if (view !== "tree" && view !== "blob" && view !== "commits") {
+ return c.notFound();
+ }
+ const refs = getGitHubRefs(owner, repo, type).then((data) => ({ ...data, view, path }));
+ return tryRenderFragment(c, "_refs.eta", refs);
});
app.get("/api/:owner/:repo/latest-commit/:branch/:path{.*}?", async (c) => {