Something went wrong. Try again.
because I got bored of customising my CV for every job
Something went wrong. Try again.
2.0 kB · 77 lines
TSX
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778import { 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<string, string> })?.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 ( <code className={cn( "bg-ctp-surface0 px-1.5 py-0.5 rounded text-ctp-red text-sm font-mono", className, )} > {displayText} </code> ); }
return ( <a href={fileUrl} target="_blank" rel="noopener noreferrer" className={cn( "text-ctp-blue hover:text-ctp-sapphire underline font-mono text-sm", className, )} title={`View ${path} in repository`} > {displayText} </a> );};