letterboxd support
This commit is contained in:
parent
7ff0398324
commit
4d58fff75d
4 changed files with 1139 additions and 556 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
getJsonFeedItemContent,
|
||||
getJsonFeedItemTitle,
|
||||
getLetterboxdActivity,
|
||||
getMalojaScrobble,
|
||||
markdownLinkRegex,
|
||||
} from "./utils.js";
|
||||
|
|
@ -29,4 +30,9 @@ export const items = [
|
|||
regex: markdownLinkRegex("scrobbles.melkat.dev"),
|
||||
getLatest: async () => getMalojaScrobble("https://scrobbles.melkat.dev"),
|
||||
},
|
||||
{
|
||||
id: "letterboxd",
|
||||
regex: markdownLinkRegex("letterboxd.com/zicklepop"),
|
||||
getLatest: async () => getLetterboxdActivity("zicklepop"),
|
||||
},
|
||||
];
|
||||
|
|
|
|||
1672
package-lock.json
generated
1672
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -22,6 +22,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"dotenv": "^17.2.3",
|
||||
"jsdom": "^27.3.0",
|
||||
"sanitize-html": "^2.17.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
utils.js
16
utils.js
|
|
@ -1,3 +1,4 @@
|
|||
import { JSDOM } from "jsdom";
|
||||
import sanitizeHtml from "sanitize-html";
|
||||
|
||||
export function markdownLinkRegex(url) {
|
||||
|
|
@ -12,7 +13,7 @@ export async function getJsonFeedItemTitle(feedUrl) {
|
|||
const data = await res.json();
|
||||
const post = data.items[0];
|
||||
const { title, image } = post;
|
||||
return image ? ` ${title}` : data.items[0].title;
|
||||
return image ? `${title} ` : title;
|
||||
}
|
||||
|
||||
export async function getJsonFeedItemContent(feedUrl) {
|
||||
|
|
@ -24,7 +25,7 @@ export async function getJsonFeedItemContent(feedUrl) {
|
|||
allowedTags: [],
|
||||
allowedAttributes: {},
|
||||
})?.trim();
|
||||
return image ? ` ${title}` : title;
|
||||
return image ? `${title} ` : title;
|
||||
}
|
||||
|
||||
export async function getMalojaScrobble(malojaUrl) {
|
||||
|
|
@ -37,3 +38,14 @@ export async function getMalojaScrobble(malojaUrl) {
|
|||
} = scrobble.track;
|
||||
return `${title}<br />by ${artists.join(", ")}`;
|
||||
}
|
||||
|
||||
export async function getLetterboxdActivity(username) {
|
||||
const res = await fetch(`https://letterboxd.com/${username}/rss/`);
|
||||
const data = await res.text();
|
||||
const dom = new JSDOM(data);
|
||||
|
||||
const item = dom.window.document.querySelector("item");
|
||||
const title = item.querySelector("title").textContent;
|
||||
const image = item.querySelector("description > img").src;
|
||||
return `${title} `;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue