changes to mentions
This commit is contained in:
parent
0ec63ea344
commit
bcf2b9a5f1
1 changed files with 21 additions and 2 deletions
|
@ -99,10 +99,10 @@ async function handleLol(body, env) {
|
|||
tags:[]
|
||||
}
|
||||
// this is the content
|
||||
let content = status.content
|
||||
let content = /**/status.content/*/body.status_text//*/// can switch for testing
|
||||
|
||||
// let's get funky with the hashtags
|
||||
content.match(/#\w+/g).filter((v,i,a) => a.indexOf(v) === i).forEach(hashtag => {
|
||||
content.match(/#\w+/g)?.filter((v,i,a) => a.indexOf(v) === i)?.forEach(hashtag => {
|
||||
const tag = hashtag.substring(1)
|
||||
const nonPascal = tag.replace(/([a-z])([A-Z])/g, "$1 $2")
|
||||
const kebab = tag.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()
|
||||
|
@ -110,6 +110,25 @@ async function handleLol(body, env) {
|
|||
content = content.replaceAll(hashtag, `[${hashtag}](/tag/${kebab}){.tag}`)
|
||||
})
|
||||
|
||||
// and similarly with fediverse mentions
|
||||
const mentions = content.match(/@[\w\-]+@[\w\-]+\.\S+/)?.filter((v,i,a) => a.indexOf(v) === i)
|
||||
console.log(mentions)
|
||||
for(let mention of mentions) {
|
||||
try{
|
||||
const handle = mention.substring(1)
|
||||
const domain = handle.substring(handle.indexOf('@') + 1)
|
||||
const webfinger = await (await fetch(`https://${domain}/.well-known/webfinger?resource=acct:${handle}`)).json()
|
||||
if(webfinger) {
|
||||
const link = webfinger.links?.find(l => l.rel == "http://webfinger.net/rel/profile-page")?.href
|
||||
|| webfinger.links?.find(l => l.rel == "me" || l.rel == "self")?.href
|
||||
|| webfinger.aliases && webfinger.aliases.length > 0 ? webfinger.aliases[0] : undefined
|
||||
|
||||
if(link) content = content.replaceAll(mention, `[${mention}](${link}){.mention}`)
|
||||
}
|
||||
}
|
||||
catch(err) { console.error(err) }
|
||||
}
|
||||
|
||||
const yamlOptions = {
|
||||
collectionStyle: 'flow',
|
||||
simpleKeys: true
|
||||
|
|
Loading…
Reference in a new issue