UNPKG

rsshub

Version:
51 lines (49 loc) 1.62 kB
import "./dist-Bog6z_OM.mjs"; import "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import { t as ofetch_default } from "./ofetch-DKl_Ma9g.mjs"; import { t as parseDate } from "./parse-date-r5WDWHno.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.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 };