From 69cf02e0189da7934847cd90dfc1b1543184a4b3 Mon Sep 17 00:00:00 2001 From: trafficlunar Date: Wed, 29 Oct 2025 22:48:30 +0000 Subject: [PATCH] feat: fancy internal links in mii descriptions --- src/app/mii/[id]/page.tsx | 73 +++++++++++++++++++++++++++++- src/components/profile-picture.tsx | 2 +- 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/app/mii/[id]/page.tsx b/src/app/mii/[id]/page.tsx index e6346b9..3456f3c 100644 --- a/src/app/mii/[id]/page.tsx +++ b/src/app/mii/[id]/page.tsx @@ -13,6 +13,7 @@ import ImageViewer from "@/components/image-viewer"; import DeleteMiiButton from "@/components/delete-mii"; import ShareMiiButton from "@/components/share-mii-button"; import ScanTutorialButton from "@/components/tutorial/scan"; +import ProfilePicture from "@/components/profile-picture"; interface Props { params: Promise<{ id: string }>; @@ -214,7 +215,77 @@ export default async function MiiPage({ params }: Props) { {/* Description */} {mii.description && (

- {mii.description} + {/* 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 = mii.description.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}; + }); + })()}

)} diff --git a/src/components/profile-picture.tsx b/src/components/profile-picture.tsx index 4bc11fe..8bda095 100644 --- a/src/components/profile-picture.tsx +++ b/src/components/profile-picture.tsx @@ -7,5 +7,5 @@ export default function ProfilePicture(props: Partial) { const { src, ...rest } = props; const [imgSrc, setImgSrc] = useState(src); - return {"profile setImgSrc("/guest.webp")} />; + return {"profile setImgSrc("/guest.webp")} />; }