letterboxd support

This commit is contained in:
Melanie Kat 2025-12-17 21:35:31 -08:00
parent 7ff0398324
commit 4d58fff75d
4 changed files with 1139 additions and 556 deletions

View file

@ -1,6 +1,7 @@
import { import {
getJsonFeedItemContent, getJsonFeedItemContent,
getJsonFeedItemTitle, getJsonFeedItemTitle,
getLetterboxdActivity,
getMalojaScrobble, getMalojaScrobble,
markdownLinkRegex, markdownLinkRegex,
} from "./utils.js"; } from "./utils.js";
@ -29,4 +30,9 @@ export const items = [
regex: markdownLinkRegex("scrobbles.melkat.dev"), regex: markdownLinkRegex("scrobbles.melkat.dev"),
getLatest: async () => getMalojaScrobble("https://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

File diff suppressed because it is too large Load diff

View file

@ -22,6 +22,7 @@
}, },
"dependencies": { "dependencies": {
"dotenv": "^17.2.3", "dotenv": "^17.2.3",
"jsdom": "^27.3.0",
"sanitize-html": "^2.17.0" "sanitize-html": "^2.17.0"
} }
} }

View file

@ -1,3 +1,4 @@
import { JSDOM } from "jsdom";
import sanitizeHtml from "sanitize-html"; import sanitizeHtml from "sanitize-html";
export function markdownLinkRegex(url) { export function markdownLinkRegex(url) {
@ -12,7 +13,7 @@ export async function getJsonFeedItemTitle(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;
return image ? `![${title}](${image}) ${title}` : data.items[0].title; return image ? `${title} ![${title}](${image})` : title;
} }
export async function getJsonFeedItemContent(feedUrl) { export async function getJsonFeedItemContent(feedUrl) {
@ -24,7 +25,7 @@ export async function getJsonFeedItemContent(feedUrl) {
allowedTags: [], allowedTags: [],
allowedAttributes: {}, allowedAttributes: {},
})?.trim(); })?.trim();
return image ? `![${title}](${image}) ${title}` : title; return image ? `${title} ![${title}](${image})` : title;
} }
export async function getMalojaScrobble(malojaUrl) { export async function getMalojaScrobble(malojaUrl) {
@ -37,3 +38,14 @@ export async function getMalojaScrobble(malojaUrl) {
} = scrobble.track; } = scrobble.track;
return `${title}<br />by ${artists.join(", ")}`; 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} ![${title}](${image})`;
}