add option to not output images

This commit is contained in:
Melanie Kat 2025-12-22 20:12:11 -08:00
parent 940627fb07
commit 5c07b91237
2 changed files with 21 additions and 9 deletions

View file

@ -61,15 +61,15 @@ For example, to get the latest post from my blog's JSON feed.
#### Basics #### Basics
- `getJsonFeedItemContent(JSONFEED_URL)`: For getting the `content_html` of a JSON feed item and when available the item's `image` - `getJsonFeedItemContent(feedUrl, showImage = true)`: For getting the `content_html` of a JSON feed item and when available the item's `image` (unless the last argument is `false`)
- `getJsonFeedItemTitle(JSONFEED_URL)`: For getting the `title` of a JSON feed item and when available the item's `image` - `getJsonFeedItemTitle(feedUrl, showImage = true)`: For getting the `title` of a JSON feed item and when available the item's `image` (unless the last argument is `false`)
- `getRSSItemTitle(RSS_URL)`: For getting the `title` of a RSS feed item - `getRSSItemTitle(RSS_URL)`: For getting the `title` of a RSS feed item
#### Service Specific #### Service Specific
- `getLetterboxdActivity(LETTERBOXD_USERNAME)`: For getting the latest item from your Letterboxd RSS feed and the image from the description - `getLetterboxdActivity(letterboxdUsername, showImage = true)`: For getting the latest item from your Letterboxd RSS feed and the image from the description (unless the last argument is `false`)
- `getMalojaScrobble(MALOJA_URL)`: For getting the latest scrobble artist and track title - `getMalojaScrobble(malojaUrl)`: For getting the latest scrobble artist and track title
- `getTraktEpisode(TRAKT_USERNAME, TRAKT_ID)`: For getting the latest watched TV episode's show name, season and episode number, episode title, and episode image - `getTraktEpisode(traktUsername, traktId, showImage = true)`: For getting the latest watched TV episode's show name, season and episode number, episode title, and episode image (unless the last argument is `false`)
## Support ## Support

View file

@ -41,16 +41,19 @@ export async function getRSSItemTitle(feedUrl) {
) )
} }
export async function getJsonFeedItemTitle(feedUrl) { export async function getJsonFeedItemTitle(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 { title, image } = post const { title, image } = post
const cleanTitle = markdownCharEscape(title) const cleanTitle = markdownCharEscape(title)
if (!showImage) {
return cleanTitle
}
return image ? `${cleanTitle} ![${cleanTitle}](${image})` : cleanTitle return image ? `${cleanTitle} ![${cleanTitle}](${image})` : cleanTitle
} }
export async function getJsonFeedItemContent(feedUrl) { 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]
@ -60,6 +63,9 @@ export async function getJsonFeedItemContent(feedUrl) {
allowedAttributes: {}, allowedAttributes: {},
})?.trim() })?.trim()
const cleanTitle = markdownCharEscape(title) const cleanTitle = markdownCharEscape(title)
if (!showImage) {
return cleanTitle
}
return image ? `${cleanTitle} ![${cleanTitle}](${image})` : cleanTitle return image ? `${cleanTitle} ![${cleanTitle}](${image})` : cleanTitle
} }
@ -76,7 +82,7 @@ export async function getMalojaScrobble(malojaUrl) {
return markdownCharEscape(`${cleanTitle}<br />by ${cleanArtists}`) return markdownCharEscape(`${cleanTitle}<br />by ${cleanArtists}`)
} }
export async function getLetterboxdActivity(username) { export async function getLetterboxdActivity(username, showImage = true) {
const res = await fetch(`https://letterboxd.com/${username}/rss/`) const res = await fetch(`https://letterboxd.com/${username}/rss/`)
const data = await res.text() const data = await res.text()
const dom = new JSDOM(data) const dom = new JSDOM(data)
@ -84,10 +90,13 @@ export async function getLetterboxdActivity(username) {
const title = item.querySelector('title').textContent const title = item.querySelector('title').textContent
const cleanTitle = markdownCharEscape(title) const cleanTitle = markdownCharEscape(title)
const image = item.querySelector('description > img').src const image = item.querySelector('description > img').src
if (!showImage) {
return cleanTitle
}
return `${cleanTitle} ![${cleanTitle}](${image})` return `${cleanTitle} ![${cleanTitle}](${image})`
} }
export async function getTraktEpisode(username, id) { export async function getTraktEpisode(username, id, showImage = true) {
const res = await fetch( const res = await fetch(
`https://trakt.tv/users/${username}/history/episodes/added/asc.atom?slurm=${process.env.TRAKT_SLURM}`, `https://trakt.tv/users/${username}/history/episodes/added/asc.atom?slurm=${process.env.TRAKT_SLURM}`,
) )
@ -96,6 +105,9 @@ export async function getTraktEpisode(username, id) {
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 cleanTitle = markdownCharEscape(title) const cleanTitle = markdownCharEscape(title)
if (!showImage) {
return cleanTitle
}
return `${cleanTitle} ![${cleanTitle}](https://widgets.trakt.tv/users/${id}/watched/thumb@2x.jpg?type=episode&image_only=1)` return `${cleanTitle} ![${cleanTitle}](https://widgets.trakt.tv/users/${id}/watched/thumb@2x.jpg?type=episode&image_only=1)`
} }