updated getRSSItemTitle and getJsonFeedItemTitle to remove markdownCharEscape usage

This commit is contained in:
dylan 2025-12-25 20:01:35 +00:00
parent a3ed5a4a82
commit 904637fb56

View file

@ -42,12 +42,10 @@ export async function getRSSItemTitle(feedUrl) {
const item = dom.window.document.querySelector('item') const item = dom.window.document.querySelector('item')
const title = item.querySelector('title').textContent const title = item.querySelector('title').textContent
const link = item.querySelector('link').textContent.trim() const link = item.querySelector('link').textContent.trim()
const cleanTitle = markdownCharEscape( const cleanTitle = sanitizeHtml(title, {
sanitizeHtml(title, { allowedTags: [],
allowedTags: [], allowedAttributes: {},
allowedAttributes: {}, })?.trim()
})?.trim(),
)
return { text: cleanTitle, url: link } return { text: cleanTitle, url: link }
} }
@ -56,12 +54,11 @@ export async function getJsonFeedItemTitle(feedUrl, showImage = true) {
const data = await res.json() const data = await res.json()
const post = data.items[0] const post = data.items[0]
const { title, image, url } = post const { title, image, url } = post
const cleanTitle = markdownCharEscape(title)
const text = !showImage const text = !showImage
? cleanTitle ? title
: image : image
? `${cleanTitle} ![${cleanTitle}](${image})` ? `${title} ![${title}](${image})`
: cleanTitle : title
return { text, url } return { text, url }
} }
@ -69,16 +66,17 @@ export async function getJsonFeedItemContent(feedUrl, showImage = true) {
const res = await fetch(feedUrl) const res = await fetch(feedUrl)
const data = await res.json() const data = await res.json()
const post = data.items[0] const post = data.items[0]
const { content_html, image } = post const { content_html, image, url } = post
const title = sanitizeHtml(content_html, { const title = sanitizeHtml(content_html, {
allowedTags: [], allowedTags: [],
allowedAttributes: {}, allowedAttributes: {},
})?.trim() })?.trim()
const cleanTitle = markdownCharEscape(title) const text = !showImage
if (!showImage) { ? title
return cleanTitle : image
} ? `${title} ![${title}](${image})`
return image ? `${cleanTitle} ![${cleanTitle}](${image})` : cleanTitle : title
return { text, url }
} }
export async function getMalojaScrobble(malojaUrl) { export async function getMalojaScrobble(malojaUrl) {
@ -89,9 +87,7 @@ export async function getMalojaScrobble(malojaUrl) {
title, title,
album: { artists }, album: { artists },
} = scrobble.track } = scrobble.track
const cleanTitle = markdownCharEscape(title) return `${title}<br />by ${artists.join(', ')}`
const cleanArtists = markdownCharEscape(artists.join(', '))
return markdownCharEscape(`${cleanTitle}<br />by ${cleanArtists}`)
} }
export async function getLetterboxdActivity(username, showImage = true) { export async function getLetterboxdActivity(username, showImage = true) {
@ -101,15 +97,14 @@ export async function getLetterboxdActivity(username, showImage = true) {
const item = dom.window.document.querySelector('item') const item = dom.window.document.querySelector('item')
const title = item.querySelector('title').textContent const title = item.querySelector('title').textContent
const link = item.querySelector('link').textContent.trim() const link = item.querySelector('link').textContent.trim()
const cleanTitle = markdownCharEscape(title)
let text = cleanTitle let text = title
if (showImage) { if (showImage) {
// Parse CDATA content as HTML to extract image // Parse CDATA content as HTML to extract image
const description = item.querySelector('description').textContent const description = item.querySelector('description').textContent
const imgMatch = description.match(/<img[^>]+src="([^"]+)"/) const imgMatch = description.match(/<img[^>]+src="([^"]+)"/)
const image = imgMatch ? imgMatch[1] : null const image = imgMatch ? imgMatch[1] : null
text = image ? `${cleanTitle} ![${cleanTitle}](${image})` : cleanTitle text = image ? `${title} ![${title}](${image})` : title
} }
return { text, url: link } return { text, url: link }
@ -124,10 +119,9 @@ export async function getTraktEpisode(username, id, showImage = true) {
const entry = dom.window.document.querySelector('entry') const entry = dom.window.document.querySelector('entry')
const title = entry.querySelector('title').textContent const title = entry.querySelector('title').textContent
const link = entry.querySelector('link').getAttribute('href') const link = entry.querySelector('link').getAttribute('href')
const cleanTitle = markdownCharEscape(title)
const text = !showImage const text = !showImage
? cleanTitle ? title
: `${cleanTitle} ![${cleanTitle}](https://widgets.trakt.tv/users/${id}/watched/thumb@2x.jpg?type=episode&image_only=1)` : `${title} ![${title}](https://widgets.trakt.tv/users/${id}/watched/thumb@2x.jpg?type=episode&image_only=1)`
return { text, url: link } return { text, url: link }
} }
@ -140,7 +134,7 @@ export async function getTraktMovie(username, showImage = true) {
const entry = dom.window.document.querySelector('entry') const entry = dom.window.document.querySelector('entry')
const title = entry.querySelector('title').textContent const title = entry.querySelector('title').textContent
const link = entry.querySelector('link').getAttribute('href') const link = entry.querySelector('link').getAttribute('href')
return { text: markdownCharEscape(title), url: link } return { text: title, url: link }
} }
export async function getTraktEpisodeAndMovie(username, id, showImage = true) { export async function getTraktEpisodeAndMovie(username, id, showImage = true) {