updated mastodon post image extraction to check for media:content first
This commit is contained in:
parent
3a8683204c
commit
469dddd539
1 changed files with 16 additions and 6 deletions
18
utils.js
18
utils.js
|
|
@ -150,9 +150,14 @@ export async function getMastodonPost(config) {
|
|||
|
||||
const link = item.querySelector('link')?.textContent.trim()
|
||||
|
||||
// extract image from description html if available
|
||||
// extract image from media:content or description html
|
||||
// check for media:content (mastodon uses this for attachments)
|
||||
const mediaContent = item.getElementsByTagName('media:content')[0]
|
||||
let image = mediaContent?.getAttribute('url') || null
|
||||
if (!image) {
|
||||
const imgMatch = description.match(/<img[^>]+src="([^"]+)"/)
|
||||
const image = imgMatch ? imgMatch[1] : null
|
||||
image = imgMatch ? imgMatch[1] : null
|
||||
}
|
||||
|
||||
// use description as the text, stripping HTML
|
||||
let cleanText = sanitizeHtml(description, {
|
||||
|
|
@ -171,9 +176,14 @@ export async function getMastodonPost(config) {
|
|||
const description = firstItem.querySelector('description')?.textContent || ''
|
||||
const link = firstItem.querySelector('link')?.textContent.trim()
|
||||
|
||||
// extract image from description html if available
|
||||
// extract image from media:content or description html
|
||||
// check for media:content (mastodon uses this for attachments)
|
||||
const mediaContent = firstItem.getElementsByTagName('media:content')[0]
|
||||
let image = mediaContent?.getAttribute('url') || null
|
||||
if (!image) {
|
||||
const imgMatch = description.match(/<img[^>]+src="([^"]+)"/)
|
||||
const image = imgMatch ? imgMatch[1] : null
|
||||
image = imgMatch ? imgMatch[1] : null
|
||||
}
|
||||
|
||||
let cleanText = sanitizeHtml(description, {
|
||||
allowedTags: [],
|
||||
|
|
|
|||
Loading…
Reference in a new issue