import Image from "next/image"; import Link from "next/link"; import { prisma } from "@/lib/prisma"; import ProfilePicture from "./profile-picture"; interface Props { text: string; className?: string; } export default function Description({ text, className }: Props) { return (

{/* Adds fancy formatting when linking to other pages on the site */} {(() => { const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || "https://tomodachishare.com"; // Match both mii and profile links const regex = new RegExp(`(${baseUrl.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&")}/(?:mii|profile)/\\d+)`, "g"); const parts = text.split(regex); return parts.map(async (part, index) => { const miiMatch = part.match(new RegExp(`^${baseUrl}/mii/(\\d+)$`)); const profileMatch = part.match(new RegExp(`^${baseUrl}/profile/(\\d+)$`)); if (miiMatch) { const id = Number(miiMatch[1]); const linkedMii = await prisma.mii.findUnique({ where: { id, }, }); if (!linkedMii) return; return ( mii {linkedMii.name} ); } if (profileMatch) { const id = Number(profileMatch[1]); const linkedProfile = await prisma.user.findUnique({ where: { id, }, }); if (!linkedProfile) return; return ( {linkedProfile.name} ); } // Regular text return {part}; }); })()}

); }