From b84492439343433ca7217ecd9fbb3c3d03679e1d Mon Sep 17 00:00:00 2001 From: Xylight Date: Fri, 26 Jul 2024 20:47:53 -0700 Subject: [PATCH] fix: photonify community and user links --- src/lib/components/markdown/markdown.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib/components/markdown/markdown.ts b/src/lib/components/markdown/markdown.ts index edd4ab1e..3c5401d9 100644 --- a/src/lib/components/markdown/markdown.ts +++ b/src/lib/components/markdown/markdown.ts @@ -124,9 +124,10 @@ md.linkify.add('u/', { }) const regexes = { - post: /^https:\/\/([a-zA-Z0-9.-]+)\/post\/(\d+)$/, - comment: /^https:\/\/([a-zA-Z0-9.-]+)\/comment\/(\d+)$/, - user: /^https:\/\/([a-zA-Z0-9.-]+)\/user\/(\d+)$/, + post: /^https:\/\/([a-zA-Z0-9.-]+)\/post\/(\d+)$/i, + comment: /^https:\/\/([a-zA-Z0-9.-]+)\/comment\/(\d+)$/i, + user: /^https:\/\/([a-zA-Z0-9.-]+)(\/u\/)([a-zA-Z0-9.-]+)$/i, + community: /^https:\/\/([a-zA-Z0-9.-]+)(\/c\/)([a-zA-Z0-9.-]+)$/i, } /** @@ -146,6 +147,11 @@ export const photonify = (link: string) => { if (regexes.user.test(link)) { const match = link.match(regexes.user) if (!match) return - return `/u/${match?.[2]}@${match?.[1]}` + return `/u/${match?.[3]}@${match?.[1]}` + } + if (regexes.community.test(link)) { + const match = link.match(regexes.community) + if (!match) return + return `/c/${match?.[3]}@${match?.[1]}` } }