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

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