UNPKG

rsshub

Version:
52 lines (50 loc) 1.7 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 "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { n as getItem, t as baseUrl } from "./utils-BrcfRI3j.mjs"; import * as cheerio from "cheerio"; //#region lib/routes/qstheory/magazine.ts const route = { path: "/magazine/:magazine", categories: ["traditional-media"], example: "/qstheory/magazine/qs", parameters: { magazine: "刊物,`qs` 为求是,`hqwglist` 为红旗文稿" }, radar: [{ source: ["www.qstheory.cn/:magazine/mulu.htm"] }], name: "在线读刊", maintainers: ["TonyRL", "cscnk52"], handler }; async function handler(ctx) { const { magazine } = ctx.req.param(); const link = `${baseUrl}/${magazine}/mulu.htm`; const yearResponse = await ofetch_default(link); const $ = cheerio.load(yearResponse); const issueResponse = await ofetch_default($(".booktitle a").toArray().map((item) => { const $item = $(item); return { title: $item.text(), link: new URL($item.attr("href"), baseUrl).href }; })[0].link); const $$ = cheerio.load(issueResponse); const list = $$(".highlight a").toArray().map((item) => { const $item = $$(item); return { title: $item.text(), link: $item.attr("href") }; }).toReversed().filter((item) => item.title); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, () => getItem(item)))); return { title: $("head title").text(), link, image: new URL($(".book img").attr("src"), link).href, item: items }; } //#endregion export { route };