feat(route): Let CAS-IGDB router accepts path argument (#14465)

* let IGDB router accepts path argument

* add support for "dqyd" column

* add example of dqyd column to docs

* Update lib/v2/cas/radar.js

---------
This commit is contained in:
panyq357
2024-02-16 21:52:42 +08:00
committed by GitHub
parent 3c086f017d
commit af8217575e
6 changed files with 80 additions and 36 deletions
+63
View File
@@ -0,0 +1,63 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const baseUrl = 'https://genetics.cas.cn';
module.exports = async (ctx) => {
const { path } = ctx.params;
const currentUrl = `${baseUrl}/${path}/`;
const { data: response } = await got(currentUrl);
const $ = cheerio.load(response);
let items;
if (path.substring(0, 3) === 'edu') {
items = $('li.box-s.h16')
.toArray()
.map((item) => {
item = $(item);
const a = item.find('a').first();
const date = item.find('.box-date').first();
return {
title: a.text(),
link: new URL(a.attr('href'), currentUrl).href,
pubDate: parseDate(date.text(), 'YYYY-MM-DD'),
};
});
} else if (path.substring(0, 4) === 'dqyd') {
items = $('div.list-tab ul li')
.toArray()
.map((item) => {
item = $(item);
const a = item.find('a').first();
const date = item.find('.right').first();
return {
title: a.text(),
link: new URL(a.attr('href'), currentUrl).href,
pubDate: parseDate(date.text(), 'YYYY-MM-DD'),
};
});
} else {
items = $('li.row.no-gutters.py-1')
.toArray()
.map((item) => {
item = $(item);
const a = item.find('a').first();
const date = item.find('.col-news-date').first();
return {
title: a.text(),
link: new URL(a.attr('href'), currentUrl).href,
pubDate: parseDate(date.text(), 'YYYY.MM.DD'),
};
});
}
ctx.state.data = {
title: $('head title').text(),
link: currentUrl,
item: items,
};
};
-29
View File
@@ -1,29 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const baseUrl = 'https://genetics.cas.cn/jixs/yg/';
const { data: response } = await got(baseUrl);
const $ = cheerio.load(response);
const items = $('li.row.no-gutters.py-1')
.toArray()
.map((item) => {
item = $(item);
const a = item.find('a').first();
const date = item.find('.col-news-date').first();
return {
title: a.text(),
link: new URL(a.attr('href'), baseUrl).href,
pubDate: parseDate(date.text(), 'YYYY.MM.DD'),
};
});
ctx.state.data = {
title: 'IGDB - 学术活动',
link: baseUrl,
item: items,
};
};
+1 -1
View File
@@ -1,6 +1,6 @@
module.exports = {
'/cg/:caty?': ['nczitzk'],
'/genetics/xshd': ['panyq357'],
'/genetics/:path+': ['panyq357'],
'/ia/yjs': ['shengmaosu'],
'/iee/kydt': ['nczitzk'],
'/is/:path+': ['Misaka13514'],
+3 -3
View File
@@ -11,10 +11,10 @@ module.exports = {
],
'www.genetics': [
{
title: '遗传与生物学研究所 - 学术活动',
title: '遗传与发育生物学研究所',
docs: 'https://docs.rsshub.app/routes/university#zhong-guo-ke-xue-yuan',
source: ['/jixs/yg', '/'],
target: '/cas/genetics/xshd',
source: ['/*path'],
target: '/cas/genetics/*path',
},
],
'www.ia': [
+1 -1
View File
@@ -1,6 +1,6 @@
module.exports = (router) => {
router.get('/cg/:caty?', require('./cg/index'));
router.get('/genetics/xshd', require('./genetics/xshd'));
router.get('/genetics/:path+', require('./genetics/index'));
router.get('/ia/yjs', require('./ia/yjs'));
router.get('/iee/kydt', require('./iee/kydt'));
router.get('/is/:path+', require('./is/index'));
+12 -2
View File
@@ -3524,9 +3524,19 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE\_TL
| xwdt2016/tzgg2016 | xwdt2016/kjdt2016 | kxcb2016/kpdt2016 |
</Route>
### 遗传与发育生物学研究所 学术活动 {#zhong-guo-ke-xue-yuan-yi-chuan-yu-fa-yu-sheng-wu-xue-yan-jiu-suo-xue-shu-huo-dong}
### 遗传与发育生物学研究所 {#zhong-guo-ke-xue-yuan-yi-chuan-yu-fa-yu-sheng-wu-xue-yan-jiu-suo}
<Route author="panyq357" example="/cas/genetics/xshd" path="/cas/genetics/xshd" radar="1" />
<Route author="panyq357" example="/cas/genetics/jixs/yg" path="/cas/genetics/:path+" paramsDesc={['路径,可在 URL 找到']} radar="1">
路径参数示例:
| 路径 | 栏目 |
| :--------------------- | :--------- |
| jixs/yg | 学术预告 |
| dtxw/kyjz | 科研进展 |
| edu/zsxx/ssszs\_187556 | 硕士生招生 |
| edu/zsxx/bsszs\_187557 | 博士生招生 |
| dqyd/djgz/dwyw | 党委要闻 |
</Route>
## 中国科学院大学 {#zhong-guo-ke-xue-yuan-da-xue}