UNPKG

rsshub

Version:
70 lines (68 loc) 1.92 kB
import "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import { t as logger_default } from "./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 { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { load } from "cheerio"; //#region lib/routes/modb/topic.ts const route = { path: "/topic/:id", categories: ["programming"], example: "/modb/topic/44158", parameters: { id: "合辑序号" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "合辑", maintainers: ["yueneiqi"], handler }; async function handler(ctx) { const baseUrl = "https://www.modb.pro"; const topicId = ctx.req.param("id"); const list = (await ofetch_default(`${baseUrl}/api/columns/getKnowledge`, { query: { pageNum: 1, pageSize: 20, columnId: topicId } })).list.map((item) => { let doc = {}; let baseLink = {}; switch (item.type) { case 0: doc = item.knowledge; baseLink = `${baseUrl}/db`; break; case 1: doc = item.dbDoc; baseLink = `${baseUrl}/doc`; break; default: logger_default.error(`unknown type ${item.type}`); } return { title: doc.title, link: `${baseLink}/${item.rid}`, pubDate: timezone(parseDate(item.createdTime), 8), author: doc.createdByName, category: doc.tags }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { item.description = load(await ofetch_default(item.link))("div.editor-content-styl.article-style").first().html(); return item; }))); return { title: "墨天轮合辑", link: `${baseUrl}/topic/${topicId}`, item: items }; } //#endregion export { route };