UNPKG

rsshub

Version:
51 lines (49 loc) 1.62 kB
import "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { load } from "cheerio"; //#region lib/routes/railway/index.ts const route = { path: "/blog", categories: ["blog"], example: "/railway/blog", url: "blog.railway.com", name: "Blog", maintainers: ["jihuayu"], handler }; async function handler(ctx) { return { title: "Railway articles", link: "https://blog.railway.com", item: await fetchArticles(Number.parseInt(ctx.req.query("limit") || "10")) }; } const fetchArticles = async (limit) => { const $ = load(await ofetch_default("https://blog.railway.com/rss.xml", { responseType: "text" }), { xml: true }); return Promise.all($("item").toArray().slice(0, limit).map((element) => { const id = $(element).find("guid").text(); return cache_default.tryGet(`railway:blogs:${id}`, async () => { const title = $(element).find("title").text(); const pubDate = $(element).find("pubDate").text(); const link = $(element).find("link").text(); const { content } = await fetchArticleDetails(link); return { guid: id, title, link, pubDate: parseDate(pubDate), description: content }; }); })); }; const fetchArticleDetails = async (url) => { return { content: load(await ofetch_default(url))("article > section ").html() ?? void 0 }; }; //#endregion export { fetchArticleDetails, fetchArticles, route };