UNPKG

rsshub

Version:
46 lines (44 loc) 1.55 kB
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { load } from "cheerio"; //#region lib/routes/ruancan/utils.ts const fetchFeed = async (ctx, currentUrl) => { currentUrl = `https://www.ruancan.com${currentUrl}`; const $ = load((await got_default({ method: "get", url: currentUrl })).data); let items = $(".item-title a").slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 15).toArray().map((item) => { item = $(item); return { title: item.text(), link: item.attr("href") }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const content = load((await got_default({ method: "get", url: item.link })).data); content(".entry-copyright").remove(); content(".entry-content div").each(function() { if (/^ruanc-\d+/.test(content(this).attr("id"))) content(this).remove(); }); content("figure").each(function() { content(this).html(`<img src="${content(this).find("a").attr("href")}">`); }); item.description = content(".entry-content").html(); item.category = content(".entry-info a[rel=\"category tag\"]").toArray().map((c) => content(c).text()); item.pubDate = parseDate(content(".entry-info .entry-date").attr("datetime")); return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; }; var utils_default = fetchFeed; //#endregion export { utils_default as t };