UNPKG

rsshub

Version:
52 lines (51 loc) 2.07 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.mjs"; import { t as timezone } from "./timezone-DE--ze1V.mjs"; import { load } from "cheerio"; //#region lib/routes/muchong/index.ts const route = { path: "/:id/:type?/:sort?", categories: ["bbs"], example: "/muchong/290", parameters: { id: "板块 id,可在板块页 URL 中找到", type: "子类别 id,可在板块页导航栏中找到,默认为 `all` 即 全部", sort: "排序,可选 `order-tid` 即 发表排序,默认为 回帖排序" }, name: "分类", maintainers: ["nczitzk"], description: `::: tip 尚不支持需要登录访问的版块 :::`, handler }; async function handler(ctx) { const { id = "", type = "all", sort = "" } = ctx.req.param(); const rootUrl = "https://muchong.com"; const decoder = new TextDecoder("gbk"); const currentUrl = `${rootUrl}/f-${id}-1${sort === "" ? "" : "-" + sort}${type === "all" ? "" : "-typeid-" + type}`; const response = await rofetch(currentUrl, { responseType: "arrayBuffer" }); const $ = load(decoder.decode(response)); const list = $(".xmc_bpt tbody .forum_list").slice(1, 10).toArray().map((element) => { const $item = $(element); return { author: $item.find(".by cite a").text(), link: `${rootUrl}${$item.find(".a_subject").attr("href")}`, title: $item.find(".thread-name span").eq(0).text() + $item.find(".a_subject").text(), pubDate: timezone(parseDate(sort === "" ? $item.find(".by cite nobr").text() : $item.find(".by .xmc_b9").eq(0).text()), 8) }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const detailResponse = await rofetch(item.link, { responseType: "arrayBuffer" }); item.description = load(decoder.decode(detailResponse))("#pid1").find(".t_fsz").html(); return item; }))); return { title: $("title").text().replace("-学术科研互动平台", ""), link: currentUrl, item: items }; } //#endregion export { route };