updated getMastodonPost to parse XML correctly and removed the atom feed function

i thought mastodon served atom for some reason
This commit is contained in:
dylan 2025-12-25 21:13:04 +00:00
parent 6ede3ee4a8
commit 117198fbf2

View file

@ -49,34 +49,10 @@ export async function getRSSItemTitle(feedUrl) {
return { text: cleanTitle, url: link } return { text: cleanTitle, url: link }
} }
export async function getAtomFeedItem(feedUrl) {
const res = await fetch(feedUrl)
const data = await res.text()
const dom = new JSDOM(data)
// check if it's rss (item) or atom (entry)
let element = dom.window.document.querySelector('entry')
if (!element) {
element = dom.window.document.querySelector('item')
}
const title = element.querySelector('title').textContent
// try to get link - atom uses href attribute, rss uses text content
const linkElement = element.querySelector('link')
const link = linkElement.getAttribute('href') || linkElement.textContent.trim()
const cleanTitle = sanitizeHtml(title, {
allowedTags: [],
allowedAttributes: {},
})?.trim()
return { text: cleanTitle, url: link }
}
export async function getMastodonPost(feedUrl) { export async function getMastodonPost(feedUrl) {
const res = await fetch(feedUrl) const res = await fetch(feedUrl)
const data = await res.text() const data = await res.text()
const dom = new JSDOM(data) const dom = new JSDOM(data, { contentType: 'text/xml' })
// get all items from the rss feed // get all items from the rss feed
const items = dom.window.document.querySelectorAll('item') const items = dom.window.document.querySelectorAll('item')