add option to not output images
This commit is contained in:
parent
940627fb07
commit
5c07b91237
2 changed files with 21 additions and 9 deletions
10
README.md
10
README.md
|
|
@ -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
|
||||||
|
|
|
||||||
20
utils.js
20
utils.js
|
|
@ -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
|
return image ? `${cleanTitle} ` : 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
|
return image ? `${cleanTitle} ` : 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} `
|
return `${cleanTitle} `
|
||||||
}
|
}
|
||||||
|
|
||||||
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} `
|
return `${cleanTitle} `
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue