UNPKG

rsshub

Version:
52 lines (50 loc) 1.7 kB
import "./dist-Bog6z_OM.mjs"; import "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import { t as ofetch_default } from "./ofetch-DKl_Ma9g.mjs"; import "./parse-date-r5WDWHno.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.mjs"; import { n as getItem, t as baseUrl } from "./utils-CZKx2I3f.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 };