| 1 | import type { Route } from "./+types/blob"; |
| 2 | import { BlobView } from "../../components/repo-view"; |
| 3 | import { highlight } from "../../lib/highlight.server"; |
| 4 | import { repos } from "../../lib/services.server"; |
| 5 | import { getViewer, unwrap } from "../../lib/session.server"; |
| 6 | |
| 7 | export function meta({ params }: Route.MetaArgs) { |
| 8 | return [{ title: `${params["*"]} · ${params.owner}/${params.repo} · g1t` }]; |
| 9 | } |
| 10 | |
| 11 | export async function loader({ params, context }: Route.LoaderArgs) { |
| 12 | const path = { namespace: params.owner, name: params.repo }; |
| 13 | const blob = unwrap( |
| 14 | await repos.blob(path, getViewer(context), params.ref, params["*"] ?? ""), |
| 15 | ); |
| 16 | return { |
| 17 | blob, |
| 18 | html: blob.text == null ? null : await highlight(blob.path, blob.text), |
| 19 | }; |
| 20 | } |
| 21 | |
| 22 | export default function Blob({ loaderData }: Route.ComponentProps) { |
| 23 | return <BlobView blob={loaderData.blob} html={loaderData.html} />; |
| 24 | } |