updated getMastodonPost to use description instead of title for non-reply items, maybe relying on forgejo actions rather than locally testing is making this messy :P

This commit is contained in:
dylan 2025-12-25 20:58:59 +00:00
parent 90c248c1b7
commit 6ede3ee4a8

View file

@ -84,31 +84,32 @@ export async function getMastodonPost(feedUrl) {
// find the first item that isn't a reply (doesn't start with @)
for (const item of items) {
const description = item.querySelector('description')?.textContent || ''
const title = item.querySelector('title')?.textContent || ''
// skip if it's a reply (starts with @ mention)
if (description.trim().startsWith('@') || title.trim().startsWith('@')) {
if (description.trim().startsWith('@')) {
continue
}
const link = item.querySelector('link')?.textContent.trim()
const cleanTitle = sanitizeHtml(title, {
// use description as the text, stripping HTML
const cleanText = sanitizeHtml(description, {
allowedTags: [],
allowedAttributes: {},
})?.trim()
return { text: cleanTitle, url: link }
return { text: cleanText, url: link }
}
// fallback to first item if no non-reply found
const firstItem = items[0]
const title = firstItem.querySelector('title').textContent
const link = firstItem.querySelector('link').textContent.trim()
const cleanTitle = sanitizeHtml(title, {
const description = firstItem.querySelector('description')?.textContent || ''
const link = firstItem.querySelector('link')?.textContent.trim()
const cleanText = sanitizeHtml(description, {
allowedTags: [],
allowedAttributes: {},
})?.trim()
return { text: cleanTitle, url: link }
return { text: cleanText, url: link }
}
export async function getJsonFeedItemTitle(feedUrl, showImage = true) {