feat(route): add 中国国家图书馆读者云平台 (#14620)

* feat(route): add 中国国家图书馆读者云平台

* fix radar

* fix typo
This commit is contained in:
Ethan Shen 2024-03-03 03:28:25 +08:00 committed by GitHub
parent 5928c5db24
commit 6a3d132008
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 172 additions and 0 deletions

View File

@ -0,0 +1,3 @@
module.exports = {
'/read/:type?': ['nczitzk'],
};

66
lib/routes/nlc/radar.js Normal file
View File

@ -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/少儿资源',
},
],
},
};

71
lib/routes/nlc/read.js Normal file
View File

@ -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,
});
};

3
lib/routes/nlc/router.js Normal file
View File

@ -0,0 +1,3 @@
export default (router) => {
router.get('/read/:type?', './read');
};

View File

@ -0,0 +1,17 @@
{{ if images }}
{{ each images image }}
{{ if image?.src }}
<figure>
<img
{{ if image.alt }}
alt="{{ image.alt }}"
{{ /if }}
src="{{ image.src }}">
</figure>
{{ /if }}
{{ /each }}
{{ /if }}
{{ if intro }}
<p>{{ intro }}</p>
{{ /if }}

View File

@ -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 |
</Route>
## 中国国家图书馆 {#zhong-guo-guo-jia-tu-shu-guan}
### 读者云平台 {#zhong-guo-guo-jia-tu-shu-guan-du-zhe-yun-ping-tai}
<Route author="nczitzk" example="/nlc/read/电子图书" path="/nlc/read/:type?" paramsDesc={['分类,见下表,默认为电子图书']} radar="1">
| [电子图书](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=少儿资源) |
| -------------------------------------------------------------- | ---------------------------------------------------------- | -------------------------------------------------------------- |
</Route>
## 中国互联网联合辟谣平台 {#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}