fix: implicit user handling
This commit is contained in:
1 parent
786597e83d
commit
9a3942562d
1 file changed
+14
-5
@@ -84,7 +84,9 @@ export const linkify = markedLinkifyIt(
|
||||
},
|
||||
},
|
||||
},
|
||||
{}
|
||||
{
|
||||
fuzzyEmail: false,
|
||||
}
|
||||
)
|
||||
|
||||
const regexes = {
|
||||
@@ -92,12 +94,18 @@ const regexes = {
|
||||
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,
|
||||
implicitUser: /^mailto:([a-z0-9_\.-]+)@(([\da-z\.-]+)\.([a-z]{2,63}))/i,
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert links to photon links
|
||||
*/
|
||||
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)) {
|
||||
const match = link.match(regexes.post)
|
||||
if (!match) return
|
||||
@@ -113,10 +121,11 @@ export const photonify = (link: string) => {
|
||||
if (!match) return
|
||||
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]}`
|
||||
if (regexes.implicitUser.test(link)) {
|
||||
const exec = regexes.implicitUser.exec(link)
|
||||
|
||||
if (!exec?.[1] || !exec?.[2]) return
|
||||
return `/u/${exec[1]}@${exec[2]}`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user