Plugin markdown update (#211)

This commit is contained in:
Simon Lecoq
2021-04-07 14:13:56 +02:00
committed by GitHub
parent f93da199d6
commit a98530dd6b
10 changed files with 87 additions and 30 deletions

View File

@@ -46,11 +46,17 @@
//Medias
if (tweet.attachments)
tweet.attachments = await Promise.all(tweet.attachments.media_keys.filter(key => medias.get(key)).map(key => medias.get(key)).map(async url => ({image:await imports.imgb64(url, {height:-1, width:450})})))
else if (linked) {
if (linked) {
const {result:{ogImage, ogSiteName:website, ogTitle:title, ogDescription:description}} = await imports.opengraph({url:linked})
const image = await imports.imgb64(ogImage?.url, {height:-1, width:450, fallback:false})
if (image)
tweet.attachments = [{image, title, description, website}]
if (image) {
if (tweet.attachments)
tweet.attachments.unshift([{image, title, description, website}])
else
tweet.attachments = [{image, title, description, website}]
}
else
tweet.text = `${tweet.text}\n${linked}`
}
}
else
@@ -68,7 +74,7 @@
//Line breaks
.replace(/\n/g, "<br/>")
//Links
.replace(new RegExp(`${tweet.urls.size ? "" : "noop^"}(${[...tweet.urls.keys()].map(url => `(?:${url})`).join("|")})`, "gi"), (_, url) => `<span class="link">${tweet.urls.get(url)}</span>`), {"&":true})
.replace(new RegExp(`${tweet.urls.size ? "" : "noop^"}(${[...tweet.urls.keys()].map(url => `(?:${url})`).join("|")})`, "gi"), (_, url) => `<a href="${url}" class="link">${tweet.urls.get(url)}</a>`), {"&":true})
}))
//Result