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:
parent
6ede3ee4a8
commit
117198fbf2
1 changed files with 1 additions and 25 deletions
26
utils.js
26
utils.js
|
|
@ -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')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue