Skip to content

Commit

Permalink
fix: photonify community and user links
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyphyn committed Jul 27, 2024
1 parent fa8ef7a commit b844924
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/lib/components/markdown/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

/**
Expand All @@ -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]}`
}
}

0 comments on commit b844924

Please sign in to comment.