summaryrefslogtreecommitdiff
path: root/cgithub/src/index.ts
diff options
context:
space:
mode:
authorJoe Mou <dev@mou.fo>2026-01-22 18:35:27 -0500
committerJoe Mou <dev@mou.fo>2026-01-23 01:02:59 -0500
commiteff2e1e7b31f046c974b88b409296af81b9f5615 (patch)
tree4e356d40c1144cbb5c8e14c679ad1e3802a0cf5e /cgithub/src/index.ts
parentd0dccc7a910a579d8c172c3d5a5a02ea3abd964d (diff)
Add blob view for displaying file contents
Diffstat (limited to 'cgithub/src/index.ts')
-rw-r--r--cgithub/src/index.ts23
1 files changed, 22 insertions, 1 deletions
diff --git a/cgithub/src/index.ts b/cgithub/src/index.ts
index df0a116..a546f13 100644
--- a/cgithub/src/index.ts
+++ b/cgithub/src/index.ts
@@ -2,7 +2,7 @@ import { Hono } from "hono";
import { serve } from "@hono/node-server";
import { serveStatic } from "@hono/node-server/serve-static";
import { Eta } from "eta";
-import { getGitHubTree } from "./scraper.js";
+import { getGitHubTree, getGitHubBlob } from "./scraper.js";
const app = new Hono();
const eta = new Eta({ views: "./views" });
@@ -30,6 +30,27 @@ app.get("/:owner/:repo/tree/:branch/:path{.*}?", async (c) => {
}
});
+app.get("/:owner/:repo/blob/:branch/:path{.*}", async (c) => {
+ try {
+ const owner = c.req.param("owner");
+ const repo = c.req.param("repo");
+ const branch = c.req.param("branch");
+ const path = c.req.param("path");
+
+ const data = await getGitHubBlob(owner, repo, branch, path);
+ const html = await eta.renderAsync("blob.eta", data);
+
+ return c.html(html);
+ } catch (error) {
+ const errorMessage =
+ error instanceof Error ? error.message : "Unknown error";
+ return c.html(
+ `<html><body><h1>Error</h1><p>${errorMessage}</p></body></html>`,
+ 500,
+ );
+ }
+});
+
const port = parseInt(process.env.PORT || "3000", 10);
serve({ fetch: app.fetch, port }, (info) => {
console.log(`Server running on http://localhost:${info.port}`);