fix: implicit user handling

This commit is contained in:
Xylight committed 2024-08-03 20:00:55 -07:00
1 parent 786597e83d
commit 9a3942562d
1 file changed
+14 -5
@@ -84,7 +84,9 @@ export const linkify = markedLinkifyIt(
}, },
}, },
}, },
{} {
fuzzyEmail: false,
}
) )
const regexes = { const regexes = {
@@ -92,12 +94,18 @@ const regexes = {
comment: /^https:\/\/([a-zA-Z0-9.-]+)\/comment\/(\d+)$/i, comment: /^https:\/\/([a-zA-Z0-9.-]+)\/comment\/(\d+)$/i,
user: /^https:\/\/([a-zA-Z0-9.-]+)(\/u\/)([a-zA-Z0-9.-_]+)$/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, community: /^https:\/\/([a-zA-Z0-9.-]+)(\/c\/)([a-zA-Z0-9.-_]+)$/i,
implicitUser: /^mailto:([a-z0-9_\.-]+)@(([\da-z\.-]+)\.([a-z]{2,63}))/i,
} }
/** /**
* Convert links to photon links * Convert links to photon links
*/ */
export const photonify = (link: string) => { export const photonify = (link: string) => {
if (regexes.community.test(link)) {
const match = link.match(regexes.community)
if (!match) return
return `/c/${match?.[3]}@${match?.[1]}`
}
if (regexes.post.test(link)) { if (regexes.post.test(link)) {
const match = link.match(regexes.post) const match = link.match(regexes.post)
if (!match) return if (!match) return
@@ -113,10 +121,11 @@ export const photonify = (link: string) => {
if (!match) return if (!match) return
return `/u/${match?.[3]}@${match?.[1]}` return `/u/${match?.[3]}@${match?.[1]}`
} }
if (regexes.community.test(link)) { if (regexes.implicitUser.test(link)) {
const match = link.match(regexes.community) const exec = regexes.implicitUser.exec(link)
if (!match) return
return `/c/${match?.[3]}@${match?.[1]}` if (!exec?.[1] || !exec?.[2]) return
return `/u/${exec[1]}@${exec[2]}`
} }
} }