From 6a3d132008a0c3518a85394110bb3758f98e496a Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Sun, 3 Mar 2024 03:28:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=AD=E5=9B=BD?= =?UTF-8?q?=E5=9B=BD=E5=AE=B6=E5=9B=BE=E4=B9=A6=E9=A6=86=E8=AF=BB=E8=80=85?= =?UTF-8?q?=E4=BA=91=E5=B9=B3=E5=8F=B0=20(#14620)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 中国国家图书馆读者云平台 * fix radar * fix typo --- lib/routes/nlc/maintainer.js | 3 + lib/routes/nlc/radar.js | 66 ++++++++++++++++++++++ lib/routes/nlc/read.js | 71 ++++++++++++++++++++++++ lib/routes/nlc/router.js | 3 + lib/routes/nlc/templates/description.art | 17 ++++++ website/docs/routes/other.mdx | 12 ++++ 6 files changed, 172 insertions(+) create mode 100644 lib/routes/nlc/maintainer.js create mode 100644 lib/routes/nlc/radar.js create mode 100644 lib/routes/nlc/read.js create mode 100644 lib/routes/nlc/router.js create mode 100644 lib/routes/nlc/templates/description.art diff --git a/lib/routes/nlc/maintainer.js b/lib/routes/nlc/maintainer.js new file mode 100644 index 000000000..2a5a4f02d --- /dev/null +++ b/lib/routes/nlc/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/read/:type?': ['nczitzk'], +}; diff --git a/lib/routes/nlc/radar.js b/lib/routes/nlc/radar.js new file mode 100644 index 000000000..607df4da5 --- /dev/null +++ b/lib/routes/nlc/radar.js @@ -0,0 +1,66 @@ +module.exports = { + 'nlc.cn': { + _name: '中国国家图书馆', + read: [ + { + title: '读者云平台', + docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai', + source: ['/outRes/outResList'], + target: (_, url) => { + url = new URL(url); + const type = url.searchParams.get('type'); + + return `/nlc/read/${type ? `/${type}` : ''}`; + }, + }, + { + title: '电子图书', + docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai', + source: ['/outRes/outResList'], + target: '/nlc/read/电子图书', + }, + { + title: '电子期刊', + docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai', + source: ['/outRes/outResList'], + target: '/nlc/read/电子期刊', + }, + { + title: '电子论文', + docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai', + source: ['/outRes/outResList'], + target: '/nlc/read/电子论文', + }, + { + title: '电子报纸', + docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai', + source: ['/outRes/outResList'], + target: '/nlc/read/电子报纸', + }, + { + title: '音视频', + docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai', + source: ['/outRes/outResList'], + target: '/nlc/read/音视频', + }, + { + title: '标准专利', + docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai', + source: ['/outRes/outResList'], + target: '/nlc/read/标准专利', + }, + { + title: '工具书', + docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai', + source: ['/outRes/outResList'], + target: '/nlc/read/工具书', + }, + { + title: '少儿资源', + docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai', + source: ['/outRes/outResList'], + target: '/nlc/read/少儿资源', + }, + ], + }, +}; diff --git a/lib/routes/nlc/read.js b/lib/routes/nlc/read.js new file mode 100644 index 000000000..f9afd6468 --- /dev/null +++ b/lib/routes/nlc/read.js @@ -0,0 +1,71 @@ +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { art } from '@/utils/render'; +import * as path from 'node:path'; + +export default async (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(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.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; + + ctx.set('data', { + item: items, + title: `${$('title').text()} - ${type}`, + link: currentUrl, + description: type, + language: 'zh', + image, + icon, + logo: icon, + subtitle: type, + author, + allowEmpty: true, + }); +}; diff --git a/lib/routes/nlc/router.js b/lib/routes/nlc/router.js new file mode 100644 index 000000000..87a34ad55 --- /dev/null +++ b/lib/routes/nlc/router.js @@ -0,0 +1,3 @@ +export default (router) => { + router.get('/read/:type?', './read'); +}; diff --git a/lib/routes/nlc/templates/description.art b/lib/routes/nlc/templates/description.art new file mode 100644 index 000000000..a3f88c9b4 --- /dev/null +++ b/lib/routes/nlc/templates/description.art @@ -0,0 +1,17 @@ +{{ if images }} + {{ each images image }} + {{ if image?.src }} +
+ {{ image.alt }} +
+ {{ /if }} + {{ /each }} +{{ /if }} + +{{ if intro }} +

{{ intro }}

+{{ /if }} \ No newline at end of file diff --git a/website/docs/routes/other.mdx b/website/docs/routes/other.mdx index 5c0fcad4e..cb9d1607f 100644 --- a/website/docs/routes/other.mdx +++ b/website/docs/routes/other.mdx @@ -995,6 +995,18 @@ Specify options (in the format of query string) in parameter `routeParams` param | usd | gbp | hkd | chf | sek | dkk | nok | jpy | cad | aud | sgd | eur | mop | thb | nzd | krw | +## 中国国家图书馆 {#zhong-guo-guo-jia-tu-shu-guan} + +### 读者云平台 {#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai} + + + | [电子图书](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=少儿资源) | + | -------------------------------------------------------------- | ---------------------------------------------------------- | -------------------------------------------------------------- | + + ## 中国互联网联合辟谣平台 {#zhong-guo-hu-lian-wang-lian-he-pi-yao-ping-tai} ### 今日辟谣 {#zhong-guo-hu-lian-wang-lian-he-pi-yao-ping-tai-jin-ri-pi-yao}