UNPKG

rsshub

Version:
83 lines (80 loc) 3.45 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import "./ofetch-BIyrKU3Y.mjs"; import "./helpers-DxBp0Pty.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/nlc/read.ts init_esm_shims(); const route = { path: "/read/:type?", categories: ["other"], example: "/nlc/read/电子图书", parameters: { type: "分类,见下表,默认为电子图书" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "读者云平台", maintainers: ["nczitzk"], handler, description: `| [电子图书](http://read.nlc.cn/outRes/outResList?type=电子图书) | [电子期刊](http://read.nlc.cn/outRes/outResList?type=电子期刊) | [电子论文](http://read.nlc.cn/outRes/outResList?type=电子论文) | [电子报纸](http://read.nlc.cn/outRes/outResList?type=电子报纸) | [音视频](http://read.nlc.cn/outRes/outResList?type=音视频) | | -------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- | ---------------------------------------------------------- | | [标准专利](http://read.nlc.cn/outRes/outResList?type=标准专利) | [工具书](http://read.nlc.cn/outRes/outResList?type=工具书) | [少儿资源](http://read.nlc.cn/outRes/outResList?type=少儿资源) | | -------------------------------------------------------------- | ---------------------------------------------------------- | -------------------------------------------------------------- |` }; async function handler(ctx) { const { type = "电子图书" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 15; const author = "中国国家图书馆"; const rootUrl = "http://read.nlc.cn"; const currentUrl = new URL(`/outRes/outResList?type=${type}`, rootUrl).href; const { data: response } = await got_default(currentUrl); const $ = load(response); const items = $("ul.YMH2019_New_GRZX_list7 li a.aa").slice(0, limit).toArray().map((item) => { item = $(item); const title = item.find("span").first().text(); return { title, link: item.prop("onclick").match(/openOutRes\('1','(.*?)','1',/)[1], description: art(path.join(__dirname, "templates/description-2f40bb93.art"), { images: item.find("div.pic img").toArray().map((i) => { i = $(i); return { src: i.prop("src"), alt: title }; }), intro: item.find("div.txt").prop("title") }), author, category: [type], guid: `nlc-read#${item.prev().prop("onclick").match(/\('(\d+)'\)/)[1]}` }; }); const image = new URL("static/style/css/images/YMH_home_main_logo.png", rootUrl).href; const icon = new URL($("link[rel=\"shortcut icon\"]").prop("href"), rootUrl).href; return { item: items, title: `${$("title").text()} - ${type}`, link: currentUrl, description: type, language: "zh", image, icon, logo: icon, subtitle: type, author, allowEmpty: true }; } //#endregion export { route };