import { cn } from "@cv/ui"; interface FileLinkProps { path: string; children?: React.ReactNode; className?: string; } const getRepoUrl = (): string => { // Try to get from environment variable const repoUrl = typeof process !== "undefined" && process.env?.["VITE_REPO_URL"] ? process.env["VITE_REPO_URL"] : ((import.meta as { env?: Record })?.env?.[ "VITE_REPO_URL" ] ?? ""); // Default to empty string if not set return repoUrl || ""; }; const getFileUrl = (path: string): string => { const repoUrl = getRepoUrl(); if (!repoUrl) { return "#"; } // Normalize path - remove leading slash if present const normalizedPath = path.startsWith("/") ? path.slice(1) : path; // Convert GitHub URL format // If it's a GitHub URL, append /blob/main/ or /tree/main/ if (repoUrl.includes("github.com")) { // Remove .git suffix if present const baseUrl = repoUrl.replace(/\.git$/, ""); // Use blob for files, tree for directories - assume blob for now return `${baseUrl}/blob/main/${normalizedPath}`; } // For other git hosts, try similar pattern return `${repoUrl}/-//blob/main/${normalizedPath}`; }; export const FileLink = ({ path, children, className }: FileLinkProps) => { const repoUrl = getRepoUrl(); const fileUrl = getFileUrl(path); const displayText = children || path; if (!repoUrl) { // If no repo URL configured, just render as code return ( {displayText} ); } return ( {displayText} ); };