mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-10 15:21:59 +08:00
feat: add 国家自然科学基金委员会 route and radar (#4153)
This commit is contained in:
@@ -1405,6 +1405,35 @@
|
||||
},
|
||||
],
|
||||
},
|
||||
'nsfc.gov.cn': {
|
||||
_name: '国家自然科学基金委员会',
|
||||
www: [
|
||||
{
|
||||
title: '基金要闻',
|
||||
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
|
||||
source: '/*',
|
||||
target: '/nsfc/news/jjyw',
|
||||
},
|
||||
{
|
||||
title: '通知公告',
|
||||
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
|
||||
source: '/*',
|
||||
target: '/nsfc/news/tzgg',
|
||||
},
|
||||
{
|
||||
title: '资助成果',
|
||||
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
|
||||
source: '/*',
|
||||
target: '/nsfc/news/zzcg',
|
||||
},
|
||||
{
|
||||
title: '科普快讯',
|
||||
docs: 'https://docs.rsshub.app/other.html#guo-jia-zi-ran-ke-xue-ji-jin-wei-yuan-hui',
|
||||
source: '/*',
|
||||
target: '/nsfc/news/kpkx',
|
||||
},
|
||||
],
|
||||
},
|
||||
'japanpost.jp': {
|
||||
_name: '日本郵便',
|
||||
'trackings.post': [
|
||||
|
||||
@@ -236,6 +236,18 @@ type 为 all 时,category 参数不支持 cost 和 free
|
||||
|
||||
<Route author="LogicJake" example="/gushiwen/recommend" path="/gushiwen/recommend"/>
|
||||
|
||||
## 国家自然科学基金委员会
|
||||
|
||||
### 新闻通知
|
||||
|
||||
<Route author="Derekmini" example="/nsfc/news/jjyw" path="/nsfc/news/:type?" :paramsDesc="['分类, 默认为 `jjyw`']" radar="1">
|
||||
|
||||
| 基金要闻 | 通知公告 | 资助成果 | 科普快讯 |
|
||||
| -------- | -------- | -------- | -------- |
|
||||
| jjyw | tzgg | zzcg | kpkx |
|
||||
|
||||
</Route>
|
||||
|
||||
## 好队友
|
||||
|
||||
### 工作机会
|
||||
|
||||
@@ -2330,4 +2330,7 @@ router.get('/lagou/jobs/:position/:city', require('./routes/lagou/jobs'));
|
||||
router.get('/yzu/home/:type', require('./routes/universities/yzu/home'));
|
||||
router.get('/yzu/yjszs/:type', require('./routes/universities/yzu/yjszs'));
|
||||
|
||||
// 国家自然科学基金委员会
|
||||
router.get('/nsfc/news/:type?', require('./routes/nsfc/news'));
|
||||
|
||||
module.exports = router;
|
||||
|
||||
92
lib/routes/nsfc/news.js
Normal file
92
lib/routes/nsfc/news.js
Normal file
@@ -0,0 +1,92 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const url = require('url');
|
||||
|
||||
const baseUrl = 'http://www.nsfc.gov.cn/';
|
||||
|
||||
const typeMap = {
|
||||
jjyw: {
|
||||
name: '基金要闻',
|
||||
url: '/publish/portal0/tab440/',
|
||||
},
|
||||
tzgg: {
|
||||
name: '通知公告',
|
||||
url: '/publish/portal0/tab442/',
|
||||
},
|
||||
zzcg: {
|
||||
name: '资助成果',
|
||||
url: '/publish/portal0/tab448/',
|
||||
},
|
||||
kpkx: {
|
||||
name: '科普快讯',
|
||||
url: '/publish/portal0/tab446/',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type || 'jjyw';
|
||||
const link = baseUrl + typeMap[type].url;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
headers: {
|
||||
Referer: baseUrl,
|
||||
},
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const urlList = $('.contentnews .clearfix')
|
||||
.slice(0, 10)
|
||||
.map((i, e) => $('a', e).attr('href'))
|
||||
.get();
|
||||
|
||||
const titleList = $('.contentnews .clearfix')
|
||||
.slice(0, 10)
|
||||
.map((i, e) => $('a', e).attr('title'))
|
||||
.get();
|
||||
|
||||
const dateList = $('.contentnews .clearfix')
|
||||
.slice(0, 10)
|
||||
.map((i, e) => $('.fr', e).text())
|
||||
.get();
|
||||
|
||||
const out = await Promise.all(
|
||||
urlList.map(async (itemUrl, index) => {
|
||||
itemUrl = url.resolve(baseUrl, itemUrl);
|
||||
if (itemUrl.indexOf('.htm') !== -1) {
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
const response = await got.get(itemUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
const single = {
|
||||
title: titleList[index],
|
||||
link: itemUrl,
|
||||
description: $('.content_xilan')
|
||||
.html()
|
||||
.replace(/src="\//g, `src="${url.resolve(baseUrl, '.')}`)
|
||||
.replace(/href="\//g, `href="${url.resolve(baseUrl, '.')}`)
|
||||
.trim(),
|
||||
pubDate: dateList[index],
|
||||
};
|
||||
ctx.cache.set(itemUrl, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
} else {
|
||||
const single = {
|
||||
title: titleList[index],
|
||||
link: itemUrl,
|
||||
description: '此链接为文件,请点击下载',
|
||||
pubDate: dateList[index],
|
||||
};
|
||||
return Promise.resolve(single);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '国家自然科学基金委员会-' + typeMap[type].name,
|
||||
link: link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
@@ -16,7 +16,7 @@ const typeMap = {
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type || 'tzgg';
|
||||
const type = ctx.params.type || 'xwdt';
|
||||
const link = baseUrl + typeMap[type].url;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
|
||||
Reference in New Issue
Block a user