updated mastodon post image extraction to check for media:content first

This commit is contained in:
dylan 2025-12-28 19:08:37 +00:00
parent 3a8683204c
commit 469dddd539

View file

@ -150,9 +150,14 @@ export async function getMastodonPost(config) {
const link = item.querySelector('link')?.textContent.trim() const link = item.querySelector('link')?.textContent.trim()
// extract image from description html if available // extract image from media:content or description html
const imgMatch = description.match(/<img[^>]+src="([^"]+)"/) // check for media:content (mastodon uses this for attachments)
const image = imgMatch ? imgMatch[1] : null const mediaContent = item.getElementsByTagName('media:content')[0]
let image = mediaContent?.getAttribute('url') || null
if (!image) {
const imgMatch = description.match(/<img[^>]+src="([^"]+)"/)
image = imgMatch ? imgMatch[1] : null
}
// use description as the text, stripping HTML // use description as the text, stripping HTML
let cleanText = sanitizeHtml(description, { let cleanText = sanitizeHtml(description, {
@ -171,9 +176,14 @@ export async function getMastodonPost(config) {
const description = firstItem.querySelector('description')?.textContent || '' const description = firstItem.querySelector('description')?.textContent || ''
const link = firstItem.querySelector('link')?.textContent.trim() const link = firstItem.querySelector('link')?.textContent.trim()
// extract image from description html if available // extract image from media:content or description html
const imgMatch = description.match(/<img[^>]+src="([^"]+)"/) // check for media:content (mastodon uses this for attachments)
const image = imgMatch ? imgMatch[1] : null const mediaContent = firstItem.getElementsByTagName('media:content')[0]
let image = mediaContent?.getAttribute('url') || null
if (!image) {
const imgMatch = description.match(/<img[^>]+src="([^"]+)"/)
image = imgMatch ? imgMatch[1] : null
}
let cleanText = sanitizeHtml(description, { let cleanText = sanitizeHtml(description, {
allowedTags: [], allowedTags: [],