Skip to content

Commit

Permalink
Add data-type-{tag,mention} to track description links
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarrough committed May 24, 2024
1 parent 0a46cfb commit 15934d3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/libs/link-tags-mentions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const linkEntitiesRegex = /(^|\s)([#@][a-z\d-]+)/gi
export function linkEntities(str, href, origin) {
if (!origin) return str
return str.replace(linkEntitiesRegex, (match, prefix, entity) => {
const type = entity.startsWith('#') ? 'hashtag' : 'mention'
const type = entity.startsWith('#') ? 'tag' : 'mention'
let url = `${origin}?search=${entity.substring(1)}`
if (type === 'mention') {
url = `${href}/${entity.substring(1)}`
}
return `<a href="${url}">${entity}</a>`
return `<a href="${url}" data-type-${type}>${entity}</a>`
})
}

0 comments on commit 15934d3

Please sign in to comment.