it has come to my attention i might need to escape markdown characters whoops
This commit is contained in:
parent
e42f3b9f85
commit
08c149e478
1 changed files with 21 additions and 9 deletions
30
utils.js
30
utils.js
|
|
@ -9,16 +9,22 @@ export function markdownLinkRegex(url) {
|
|||
)
|
||||
}
|
||||
|
||||
export function markdownCharEscape(text) {
|
||||
return text.replaceAll('-', '\\-')
|
||||
}
|
||||
|
||||
export async function getRSSItemTitle(feedUrl) {
|
||||
const res = await fetch(feedUrl)
|
||||
const data = await res.text()
|
||||
const dom = new JSDOM(data)
|
||||
const item = dom.window.document.querySelector('item')
|
||||
const title = item.querySelector('title').textContent
|
||||
return sanitizeHtml(title, {
|
||||
allowedTags: [],
|
||||
allowedAttributes: {},
|
||||
})?.trim()
|
||||
return markdownCharEscape(
|
||||
sanitizeHtml(title, {
|
||||
allowedTags: [],
|
||||
allowedAttributes: {},
|
||||
})?.trim(),
|
||||
)
|
||||
}
|
||||
|
||||
export async function getJsonFeedItemTitle(feedUrl) {
|
||||
|
|
@ -26,7 +32,8 @@ export async function getJsonFeedItemTitle(feedUrl) {
|
|||
const data = await res.json()
|
||||
const post = data.items[0]
|
||||
const { title, image } = post
|
||||
return image ? `${title} ` : title
|
||||
const cleanTitle = markdownCharEscape(title)
|
||||
return image ? `${cleanTitle} ` : cleanTitle
|
||||
}
|
||||
|
||||
export async function getJsonFeedItemContent(feedUrl) {
|
||||
|
|
@ -38,7 +45,8 @@ export async function getJsonFeedItemContent(feedUrl) {
|
|||
allowedTags: [],
|
||||
allowedAttributes: {},
|
||||
})?.trim()
|
||||
return image ? `${title} ` : title
|
||||
const cleanTitle = markdownCharEscape(title)
|
||||
return image ? `${cleanTitle} ` : cleanTitle
|
||||
}
|
||||
|
||||
export async function getMalojaScrobble(malojaUrl) {
|
||||
|
|
@ -49,7 +57,9 @@ export async function getMalojaScrobble(malojaUrl) {
|
|||
title,
|
||||
album: { artists },
|
||||
} = scrobble.track
|
||||
return `${title}<br />by ${artists.join(', ')}`
|
||||
const cleanTitle = markdownCharEscape(title)
|
||||
const cleanArtists = markdownCharEscape(artists.join(', '))
|
||||
return markdownCharEscape(`${cleanTitle}<br />by ${cleanArtists}`)
|
||||
}
|
||||
|
||||
export async function getLetterboxdActivity(username) {
|
||||
|
|
@ -58,8 +68,9 @@ export async function getLetterboxdActivity(username) {
|
|||
const dom = new JSDOM(data)
|
||||
const item = dom.window.document.querySelector('item')
|
||||
const title = item.querySelector('title').textContent
|
||||
const cleanTitle = markdownCharEscape(title)
|
||||
const image = item.querySelector('description > img').src
|
||||
return `${title} `
|
||||
return `${cleanTitle} `
|
||||
}
|
||||
|
||||
export async function getTraktEpisode(username, id) {
|
||||
|
|
@ -70,5 +81,6 @@ export async function getTraktEpisode(username, id) {
|
|||
const dom = new JSDOM(data)
|
||||
const entry = dom.window.document.querySelector('entry')
|
||||
const title = entry.querySelector('title').textContent
|
||||
return `${title} `
|
||||
const cleanTitle = markdownCharEscape(title)
|
||||
return `${cleanTitle} `
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue