UNPKG

rsshub

Version:
109 lines (107 loc) 2.93 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/chuapp/chuapp.ts const route = { path: "/:category?", categories: ["game"], example: "/chuapp/daily", parameters: { category: "栏目分类,见下表" }, description: ` | \`category\` | 栏目分类 | | ------------ | ------- | | \`daily\` | 每日聚焦 | | \`pcz\` | 最好玩 | | \`night\` | 触乐夜话 | | \`news\` | 动态资讯 | `, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "分类", maintainers: ["dousha"], radar: [{ source: ["chuapp.com/category/:category"], target: "/:category" }, { source: ["chuapp.com/tag/index/id/20369.html"], target: "/night" }], handler }; const baseUrl = "https://www.chuapp.com"; const pathLut = { daily: { title: "每日聚焦", suffix: "/category/daily" }, pcz: { title: "最好玩", suffix: "/category/pcz" }, night: { title: "触乐夜话", suffix: "/tag/index/id/20369.html" }, news: { title: "动态资讯", suffix: "/category/zsyx" }, zsyx: { title: "动态资讯", suffix: "/category/zsyx" } }; function isValidArticle(article) { return "title" in article && "link" in article && article.title !== null && article.link !== null; } function toJavaScriptTimestamp(x) { return x ? Number(x) * 1e3 : 0; } async function handler(ctx) { const { category = "night" } = ctx.req.param(); const subpath = pathLut[category]; if (!subpath) return null; const targetUrl = `${baseUrl}${subpath.suffix}`; const $ = load(await ofetch_default(targetUrl)); const processedItems = $("a.fn-clear").toArray().map((element) => ({ title: $(element).attr("title"), link: $(element).attr("href") })).filter((article) => isValidArticle(article)).map((article) => { if (article.link.startsWith("/")) return article; return { title: article.title, link: `/${article.link}` }; }).map((article) => { const fullArticleUrl = `${baseUrl}${article.link}`; return cache_default.tryGet(fullArticleUrl, async () => { const s = load(await ofetch_default(fullArticleUrl)); return { title: article.title, link: article.link, description: s(".content .the-content").html() || "", pubDate: parseDate(toJavaScriptTimestamp(s(".friendly_time").attr("data-time"))), author: s(".author-time .fn-left").text() || "" }; }); }); const items = await Promise.all(processedItems); return { title: `触乐 - ${subpath.title}`, link: targetUrl, item: items }; } //#endregion export { route };