diff options
| author | Joe Mou <dev@mou.fo> | 2026-01-22 18:35:27 -0500 |
|---|---|---|
| committer | Joe Mou <dev@mou.fo> | 2026-01-23 01:02:59 -0500 |
| commit | 0dfa9814ec998487c4f76e3418e0a232dbcceb7d (patch) | |
| tree | 2d2140707ba93c7015c8956759f0898437b6555b /src/index.ts | |
| parent | 4bbc0c19076dc8490c451a1f535f3e018fb8dda3 (diff) | |
Add blob view for displaying file contents
Diffstat (limited to 'src/index.ts')
| -rw-r--r-- | src/index.ts | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/index.ts b/src/index.ts index df0a116..a546f13 100644 --- a/src/index.ts +++ b/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}`); |
