Skip to content

Commit

Permalink
feat: add dynamic linking for user mentions in posts
Browse files Browse the repository at this point in the history
  • Loading branch information
akhileshthite committed Apr 15, 2024
1 parent 49c0559 commit 9808518
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions post.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,18 @@ class DistributedPost extends HTMLElement {
postContent.classList.add('post-content')

// Determine content source based on structure of jsonLdData
const contentSource =
jsonLdData.content || (jsonLdData.object && jsonLdData.object.content)
let contentSource = jsonLdData.content || (jsonLdData.object && jsonLdData.object.content)
// Check if the content has a mention and update the href attribute
if (jsonLdData.tag && jsonLdData.tag.some(tag => tag.type === 'Mention')) {
console.log(jsonLdData.tag.type)
jsonLdData.tag.forEach(tag => {
if (tag.type === 'Mention') {
// Replace the href with the profile link
const regex = new RegExp(`href="${tag.href}"`, 'g')
contentSource = contentSource.replace(regex, `href="/profile.html?actor=${encodeURIComponent(tag.href)}"`)
}
})
}

// Determine if the content is marked as sensitive in either the direct jsonLdData or within jsonLdData.object
const isSensitive =
Expand Down

0 comments on commit 9808518

Please sign in to comment.