Skip to content

Commit 6a3d132

Browse files
authored
feat(route): add 中国国家图书馆读者云平台 (#14620)
* feat(route): add 中国国家图书馆读者云平台 * fix radar * fix typo
1 parent 5928c5d commit 6a3d132

File tree

6 files changed

+172
-0
lines changed

6 files changed

+172
-0
lines changed

lib/routes/nlc/maintainer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
'/read/:type?': ['nczitzk'],
3+
};

lib/routes/nlc/radar.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
module.exports = {
2+
'nlc.cn': {
3+
_name: '中国国家图书馆',
4+
read: [
5+
{
6+
title: '读者云平台',
7+
docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai',
8+
source: ['/outRes/outResList'],
9+
target: (_, url) => {
10+
url = new URL(url);
11+
const type = url.searchParams.get('type');
12+
13+
return `/nlc/read/${type ? `/${type}` : ''}`;
14+
},
15+
},
16+
{
17+
title: '电子图书',
18+
docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai',
19+
source: ['/outRes/outResList'],
20+
target: '/nlc/read/电子图书',
21+
},
22+
{
23+
title: '电子期刊',
24+
docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai',
25+
source: ['/outRes/outResList'],
26+
target: '/nlc/read/电子期刊',
27+
},
28+
{
29+
title: '电子论文',
30+
docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai',
31+
source: ['/outRes/outResList'],
32+
target: '/nlc/read/电子论文',
33+
},
34+
{
35+
title: '电子报纸',
36+
docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai',
37+
source: ['/outRes/outResList'],
38+
target: '/nlc/read/电子报纸',
39+
},
40+
{
41+
title: '音视频',
42+
docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai',
43+
source: ['/outRes/outResList'],
44+
target: '/nlc/read/音视频',
45+
},
46+
{
47+
title: '标准专利',
48+
docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai',
49+
source: ['/outRes/outResList'],
50+
target: '/nlc/read/标准专利',
51+
},
52+
{
53+
title: '工具书',
54+
docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai',
55+
source: ['/outRes/outResList'],
56+
target: '/nlc/read/工具书',
57+
},
58+
{
59+
title: '少儿资源',
60+
docs: 'https://docs.rsshub.app/routes/other#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai',
61+
source: ['/outRes/outResList'],
62+
target: '/nlc/read/少儿资源',
63+
},
64+
],
65+
},
66+
};

lib/routes/nlc/read.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import got from '@/utils/got';
2+
import { load } from 'cheerio';
3+
import { art } from '@/utils/render';
4+
import * as path from 'node:path';
5+
6+
export default async (ctx) => {
7+
const { type = '电子图书' } = ctx.req.param();
8+
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 15;
9+
10+
const author = '中国国家图书馆';
11+
12+
const rootUrl = 'http://read.nlc.cn';
13+
const currentUrl = new URL(`/outRes/outResList?type=${type}`, rootUrl).href;
14+
15+
const { data: response } = await got(currentUrl);
16+
17+
const $ = load(response);
18+
19+
const items = $('ul.YMH2019_New_GRZX_list7 li a.aa')
20+
.slice(0, limit)
21+
.toArray()
22+
.map((item) => {
23+
item = $(item);
24+
25+
const title = item.find('span').first().text();
26+
27+
return {
28+
title,
29+
link: item.prop('onclick').match(/openOutRes\('1','(.*?)','1',/)[1],
30+
description: art(path.join(__dirname, 'templates/description.art'), {
31+
images: item
32+
.find('div.pic img')
33+
.toArray()
34+
.map((i) => {
35+
i = $(i);
36+
37+
return {
38+
src: i.prop('src'),
39+
alt: title,
40+
};
41+
}),
42+
intro: item.find('div.txt').prop('title'),
43+
}),
44+
author,
45+
category: [type],
46+
guid: `nlc-read#${
47+
item
48+
.prev()
49+
.prop('onclick')
50+
.match(/\('(\d+)'\)/)[1]
51+
}`,
52+
};
53+
});
54+
55+
const image = new URL('static/style/css/images/YMH_home_main_logo.png', rootUrl).href;
56+
const icon = new URL($('link[rel="shortcut icon"]').prop('href'), rootUrl).href;
57+
58+
ctx.set('data', {
59+
item: items,
60+
title: `${$('title').text()} - ${type}`,
61+
link: currentUrl,
62+
description: type,
63+
language: 'zh',
64+
image,
65+
icon,
66+
logo: icon,
67+
subtitle: type,
68+
author,
69+
allowEmpty: true,
70+
});
71+
};

lib/routes/nlc/router.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default (router) => {
2+
router.get('/read/:type?', './read');
3+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{ if images }}
2+
{{ each images image }}
3+
{{ if image?.src }}
4+
<figure>
5+
<img
6+
{{ if image.alt }}
7+
alt="{{ image.alt }}"
8+
{{ /if }}
9+
src="{{ image.src }}">
10+
</figure>
11+
{{ /if }}
12+
{{ /each }}
13+
{{ /if }}
14+
15+
{{ if intro }}
16+
<p>{{ intro }}</p>
17+
{{ /if }}

website/docs/routes/other.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,18 @@ Specify options (in the format of query string) in parameter `routeParams` param
995995
| usd | gbp | hkd | chf | sek | dkk | nok | jpy | cad | aud | sgd | eur | mop | thb | nzd | krw |
996996
</Route>
997997

998+
## 中国国家图书馆 {#zhong-guo-guo-jia-tu-shu-guan}
999+
1000+
### 读者云平台 {#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai}
1001+
1002+
<Route author="nczitzk" example="/nlc/read/电子图书" path="/nlc/read/:type?" paramsDesc={['分类,见下表,默认为电子图书']} radar="1">
1003+
| [电子图书](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=音视频) |
1004+
| -------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- | ---------------------------------------------------------- |
1005+
1006+
| [标准专利](http://read.nlc.cn/outRes/outResList?type=标准专利) | [工具书](http://read.nlc.cn/outRes/outResList?type=工具书) | [少儿资源](http://read.nlc.cn/outRes/outResList?type=少儿资源) |
1007+
| -------------------------------------------------------------- | ---------------------------------------------------------- | -------------------------------------------------------------- |
1008+
</Route>
1009+
9981010
## 中国互联网联合辟谣平台 {#zhong-guo-hu-lian-wang-lian-he-pi-yao-ping-tai}
9991011

10001012
### 今日辟谣 {#zhong-guo-hu-lian-wang-lian-he-pi-yao-ping-tai-jin-ri-pi-yao}

0 commit comments

Comments
 (0)