UNPKG

rsshub

Version:
46 lines (45 loc) 1.65 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/whb/zhuzhan.ts const route = { path: "/:category", categories: ["traditional-media"], example: "/whb/bihui", parameters: { category: "文汇报分类名,可在该分类的 URL 中找到(即 https://www.whb.cn/zhuzhan/:category/index.html)" }, name: "分类", maintainers: ["hoilc"], handler }; async function handler(ctx) { const { category } = ctx.req.param(); const base = "https://www.whb.cn"; const url = `${base}/zhuzhan/${category}/index.html`; const $ = load(await rofetch(url)); const categoryName = $(".title_jingpinhui > a").first().text(); const list = $(".info_jingpinhui").toArray().map((item) => { const title = $(item).find(".title > a"); return { title: title.text(), link: `${base}${title.attr("href")}` }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const $ = load(await rofetch(item.link)); const dateAndAuthor = $(".content_other").text(); const dateString = dateAndAuthor.split("\n", 1)[0].slice(3); item.author = dateAndAuthor.split(":").at(-1); item.description = $(".content_info").html(); item.pubDate = timezone(parseDate(dateString, "YYYY年MM月DD日 HH:mm:ss"), 8); return item; }))); return { title: `文汇报 - ${categoryName}`, link: url, item: items.filter((item) => item.description) }; } //#endregion export { route };