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:
parent
90c248c1b7
commit
6ede3ee4a8
1 changed files with 9 additions and 8 deletions
17
utils.js
17
utils.js
|
|
@ -84,31 +84,32 @@ export async function getMastodonPost(feedUrl) {
|
||||||
// find the first item that isn't a reply (doesn't start with @)
|
// find the first item that isn't a reply (doesn't start with @)
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const description = item.querySelector('description')?.textContent || ''
|
const description = item.querySelector('description')?.textContent || ''
|
||||||
const title = item.querySelector('title')?.textContent || ''
|
|
||||||
|
|
||||||
// skip if it's a reply (starts with @ mention)
|
// skip if it's a reply (starts with @ mention)
|
||||||
if (description.trim().startsWith('@') || title.trim().startsWith('@')) {
|
if (description.trim().startsWith('@')) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const link = item.querySelector('link')?.textContent.trim()
|
const link = item.querySelector('link')?.textContent.trim()
|
||||||
const cleanTitle = sanitizeHtml(title, {
|
|
||||||
|
// use description as the text, stripping HTML
|
||||||
|
const cleanText = sanitizeHtml(description, {
|
||||||
allowedTags: [],
|
allowedTags: [],
|
||||||
allowedAttributes: {},
|
allowedAttributes: {},
|
||||||
})?.trim()
|
})?.trim()
|
||||||
|
|
||||||
return { text: cleanTitle, url: link }
|
return { text: cleanText, url: link }
|
||||||
}
|
}
|
||||||
|
|
||||||
// fallback to first item if no non-reply found
|
// fallback to first item if no non-reply found
|
||||||
const firstItem = items[0]
|
const firstItem = items[0]
|
||||||
const title = firstItem.querySelector('title').textContent
|
const description = firstItem.querySelector('description')?.textContent || ''
|
||||||
const link = firstItem.querySelector('link').textContent.trim()
|
const link = firstItem.querySelector('link')?.textContent.trim()
|
||||||
const cleanTitle = sanitizeHtml(title, {
|
const cleanText = sanitizeHtml(description, {
|
||||||
allowedTags: [],
|
allowedTags: [],
|
||||||
allowedAttributes: {},
|
allowedAttributes: {},
|
||||||
})?.trim()
|
})?.trim()
|
||||||
return { text: cleanTitle, url: link }
|
return { text: cleanText, url: link }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getJsonFeedItemTitle(feedUrl, showImage = true) {
|
export async function getJsonFeedItemTitle(feedUrl, showImage = true) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue