UNPKG

rsshub

Version:
81 lines (79 loc) 3.16 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import path from "node:path"; //#region lib/routes/newslaundry/utils.ts init_esm_shims(); const rootUrl = "https://www.newslaundry.com"; async function fetchCollection(collectionSlug, customUrl, skipFirstItem = false) { const apiUrl = `${rootUrl}/api/v1/collections/${collectionSlug}`; const currentUrl = customUrl || `${rootUrl}/${collectionSlug}`; const response = await ofetch_default(apiUrl); if (!response.items || !response.items.length) throw new Error("No articles found"); const items = (skipFirstItem ? response.items.slice(1) : response.items).map((item) => processStory(item.story)); return { title: `${response.name} - Newslaundry`, description: response.summary || `${response.name} articles from Newslaundry`, link: currentUrl, item: items, language: "en", logo: `${rootUrl}/favicon.ico`, icon: `${rootUrl}/favicon.ico` }; } function processStory(story) { const articleUrl = story.url; const pubDate = story["published-at"] ? parseDate(story["published-at"]) : null; const heroImage = story["hero-image-s3-key"] ? `https://media.assettype.com/${story["hero-image-s3-key"]}?auto=format%2Ccompress&fit=max&dpr=1.0&format=webp` : null; const elements = story.cards?.flatMap((card) => card?.["story-elements"]?.map((element) => { if (element.type === "text" && element.text) return { type: "text", text: element.text }; else if (element.type === "image" && element["image-s3-key"]) return { type: "image", url: `https://media.assettype.com/${element["image-s3-key"]}?auto=format%2Ccompress&format=webp`, alt: element["alt-text"] || "", title: element.title || "" }; else if (element.type === "jsembed" && element["embed-js"]) try { return { type: "jsembed", content: Buffer.from(element["embed-js"], "base64").toString() }; } catch { return null; } else if (element.type === "youtube-video" && element.url) return { type: "youtube-video", url: element.url, embedUrl: element["embed-url"] || "" }; return null; }).filter(Boolean) || []) || []; const content = art(path.join(__dirname, "templates/description-d23336fb.art"), { heroImage, heroAlt: story["hero-image-alt-text"] || "", heroCaption: story["hero-image-caption"] || "", heroAttribution: story["hero-image-attribution"], elements, subheadline: story.subheadline }); const authors = story.authors?.map((author) => ({ name: author.name, url: author.slug ? `${rootUrl}/author/${author.slug}` : void 0 })) || []; return { title: story.headline, link: articleUrl, image: heroImage, description: content || story.subheadline, pubDate, updated: story["last-correction-published-at"] ? parseDate(story["last-correction-published-at"]) : void 0, author: authors.length > 0 ? authors : story["author-name"], category: story.tags?.map((tag) => tag.name) || [] }; } //#endregion export { rootUrl as n, fetchCollection as t };