flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/apps/web/app/routes/repo/blob.tsx

38 lines1,427 bytesCodeBlame
1import type { Route } from "./+types/blob";
2import { page } from "../../lib/meta";
3import { BlobView } from "../../components/repo-view";
4import { highlight, highlightLines } from "../../lib/highlight.server";
5import { repos } from "../../lib/services.server";
6import { getViewer, unwrap } from "../../lib/session.server";
7
8export function meta({ params, ...args }: Route.MetaArgs) {
9 return page(args, { title: `${params["*"]} · ${params.owner}/${params.repo} · g1t` });
10}
11
12export async function loader({ params, context, request }: Route.LoaderArgs) {
13 const viewer = getViewer(context);
14 const path = { namespace: params.owner, name: params.repo };
15 const file = params["*"] ?? "";
16 const wantsBlame = new URL(request.url).searchParams.has("blame");
17 const [found, blame] = await Promise.all([
18 repos.blob(path, viewer, params.ref, file),
19 wantsBlame ? repos.blame(path, viewer, params.ref, file) : null,
20 ]);
21 const blob = unwrap(found);
22 if (blame?.ok && blob.text != null) {
23 return {
24 blob,
25 html: null,
26 blame: { blame: blame.value, lines: await highlightLines(blob.path, blob.text) },
27 };
28 }
29 return {
30 blob,
31 html: blob.text == null ? null : await highlight(blob.path, blob.text),
32 blame: null,
33 };
34}
35
36export default function Blob({ loaderData }: Route.ComponentProps) {
37 return <BlobView blob={loaderData.blob} html={loaderData.html} blame={loaderData.blame} />;
38}