import { notFound } from "next/navigation"; import Link from "next/link"; import { getRepository, getRepoFile } from "@/actions/repositories"; import { CodeViewer } from "@/components/code-viewer"; import { Badge } from "@/components/ui/badge"; import { Lock, Globe, ChevronRight, Home, FileCode } from "lucide-react"; const LANGUAGE_MAP: Record = { ts: "typescript", tsx: "typescript", js: "javascript", jsx: "javascript", py: "python", rb: "ruby", go: "go", rs: "rust", java: "java", md: "markdown", json: "json", yaml: "yaml", yml: "yaml", css: "css", html: "html", sh: "bash", bash: "bash", zsh: "bash", }; function getLanguage(filename: string): string { const ext = filename.split(".").pop()?.toLowerCase() || ""; return LANGUAGE_MAP[ext] || "text"; } export default async function BlobPage({ params }: { params: Promise<{ username: string; repo: string; path: string[] }> }) { const { username, repo: repoName, path: pathSegments } = await params; const branch = pathSegments[0]; const filePath = pathSegments.slice(1).join("/"); const repo = await getRepository(username, repoName); if (!repo) { notFound(); } const file = await getRepoFile(username, repoName, branch, filePath); if (!file) { notFound(); } const pathParts = filePath.split("/").filter(Boolean); const fileName = pathParts[pathParts.length - 1]; const language = getLanguage(fileName); const lineCount = file.content.split("\n").length; return (
{username} / {repoName} {repo.visibility === "private" ? ( <> Private ) : ( <> Public )}
{lineCount} lines
); }