mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat(route): add 国务院国有资产监督管理委员会 (#12875)
This commit is contained in:
+47
-45
@@ -1,74 +1,68 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const types = {
|
||||
jjyw: {
|
||||
title: '基金要闻',
|
||||
url: '/publish/portal0/tab440/',
|
||||
},
|
||||
tzgg: {
|
||||
title: '通知公告',
|
||||
url: '/publish/portal0/tab442/',
|
||||
},
|
||||
zzcg: {
|
||||
title: '资助成果',
|
||||
url: '/publish/portal0/tab448/',
|
||||
},
|
||||
kpkx: {
|
||||
title: '科普快讯',
|
||||
url: '/publish/portal0/tab446/',
|
||||
},
|
||||
};
|
||||
const shortcuts = require('./shortcuts');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type ?? 'jjyw';
|
||||
let thePath = ctx.path.replace(/^\/nsfc/, '');
|
||||
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;
|
||||
|
||||
const shortcutMatches = thePath.match(/(\/news)?\/([\w-]+)/);
|
||||
|
||||
if (shortcutMatches) {
|
||||
const shortcut = shortcutMatches[2];
|
||||
if (shortcuts.hasOwnProperty(shortcut)) {
|
||||
thePath = shortcuts[shortcut];
|
||||
}
|
||||
}
|
||||
|
||||
const rootUrl = 'https://www.nsfc.gov.cn';
|
||||
const currentUrl = `${rootUrl}${types[type].url}`;
|
||||
const currentUrl = new URL((/\/more$/.test(thePath) ? `${thePath}.htm` : thePath) || 'publish/portal0/tab442/', rootUrl).href;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
const { data: response } = await got(currentUrl, {
|
||||
https: {
|
||||
rejectUnauthorized: false,
|
||||
},
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
let items = $('.fl a')
|
||||
let items = $('span.fl a, ul.dp_lia li a')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
const link = item.attr('href');
|
||||
|
||||
return {
|
||||
title: item.attr('title'),
|
||||
link: `${/^http/.test(link) ? '' : rootUrl}${link}`,
|
||||
pubDate: parseDate(item.parent().next().text()),
|
||||
title: item.prop('title') ?? item.text(),
|
||||
link: new URL(item.prop('href'), rootUrl).href,
|
||||
guid: `nsfc-${item.prop('id')}`,
|
||||
pubDate: parseDate(item.next().text().replace(/\[|\]/g, '', ['YYYY-MM-DD', 'YY-MM-DD'])),
|
||||
};
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
if (/nsfc\.gov\.cn/.test(item.link)) {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
https: {
|
||||
rejectUnauthorized: false,
|
||||
},
|
||||
});
|
||||
const { data: detailResponse } = await got(item.link, {
|
||||
https: {
|
||||
rejectUnauthorized: false,
|
||||
},
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
const content = cheerio.load(detailResponse);
|
||||
|
||||
item.description = content('.content_xilan').html();
|
||||
item.pubDate = timezone(parseDate(content('meta[name="docdate"]').attr('content')), +8);
|
||||
}
|
||||
item.title = content('div.title_xilan').text();
|
||||
item.description = content('#zoom').html();
|
||||
item.author = content('meta[name="docauthor"]').prop('content');
|
||||
item.category = [content('meta[name="channel"]').prop('content'), content('meta[name="docsource"]').prop('content')];
|
||||
item.pubDate = parseDate(
|
||||
content('div.line_xilan')
|
||||
.text()
|
||||
.match(/日期 (\d{4}-\d{2}-\d{2})/)[1]
|
||||
);
|
||||
|
||||
return item;
|
||||
})
|
||||
@@ -76,8 +70,16 @@ module.exports = async (ctx) => {
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `国家自然科学基金委员会 - ${$('title').text()}`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
title: `国家自然科学基金委员会 - ${$('#ess_essBREADCRUMB_lblBreadCrumb a.break')
|
||||
.toArray()
|
||||
.slice(1)
|
||||
.map((a) => $(a).text())
|
||||
.join(' - ')}`,
|
||||
link: currentUrl,
|
||||
description: $('meta[name="DESCRIPTION"]').prop('content'),
|
||||
language: 'zh-cn',
|
||||
subtitle: $('meta[name="KEYWORDS"]').prop('content'),
|
||||
author: $('meta[name="AUTHOR"]').prop('content'),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
module.exports = {
|
||||
// 基金要闻 - 基金要闻 https://www.nsfc.gov.cn/publish/portal0/tab440/
|
||||
jjyw: '/publish/portal0/tab440/',
|
||||
|
||||
// 基金要闻 - 通知公告 https://www.nsfc.gov.cn/publish/portal0/tab442/
|
||||
tzgg: '/publish/portal0/tab442/',
|
||||
|
||||
// 基金要闻 - 部门动态 https://www.nsfc.gov.cn/publish/portal0/tab445/
|
||||
bmdt: '/publish/portal0/tab445/',
|
||||
|
||||
// 基金要闻 - 科普快讯 https://www.nsfc.gov.cn/publish/portal0/tab446/
|
||||
kpkx: '/publish/portal0/tab446/',
|
||||
|
||||
// 基金要闻 - 资助成果 https://www.nsfc.gov.cn/publish/portal0/tab448/
|
||||
zzcg: '/publish/portal0/tab448/',
|
||||
|
||||
// 政策法规 - 国家自然科学基金条例 https://www.nsfc.gov.cn/publish/portal0/tab471/
|
||||
'zcfg-jjtl': '/publish/portal0/tab471/',
|
||||
|
||||
// 政策法规 - 国家自然科学基金发展规划 https://www.nsfc.gov.cn/publish/portal0/tab473/
|
||||
'zcfg-fzgh': '/publish/portal0/tab473/',
|
||||
|
||||
// 政策法规 - 国家自然科学基金规章制度 https://www.nsfc.gov.cn/publish/portal0/tab475/
|
||||
'zcfg-gzzd': '/publish/portal0/tab475/',
|
||||
|
||||
// 政策法规 - 国家科学技术相关法律法规 https://www.nsfc.gov.cn/publish/portal0/tab609/
|
||||
'zcfg-flfg': '/publish/portal0/tab609/',
|
||||
|
||||
// 管理科学部 - 工作动态 https://www.nsfc.gov.cn/publish/portal0/tab1210/
|
||||
'glkxb-gzdt': '/publish/portal0/tab1210/',
|
||||
|
||||
// 管理科学部 - 通知公告 https://www.nsfc.gov.cn/publish/portal0/tab1212/
|
||||
'glkxb-tzgg': '/publish/portal0/tab1212/',
|
||||
|
||||
// 管理科学部 - 资助成果 https://www.nsfc.gov.cn/publish/portal0/tab1213/
|
||||
'glkxb-zzcg': '/publish/portal0/tab1213/',
|
||||
|
||||
// 国际合作局 - 项目指南 https://www.nsfc.gov.cn/publish/portal0/tab1356/
|
||||
'gjhzj-xmzn': '/publish/portal0/tab1356/',
|
||||
|
||||
// 国际合作局 - 初审结果 https://www.nsfc.gov.cn/publish/portal0/tab1361/
|
||||
'gjhzj-csjg': '/publish/portal0/tab1361/',
|
||||
|
||||
// 国际合作局 - 批准通知 https://www.nsfc.gov.cn/publish/portal0/tab1362/
|
||||
'gjhzj-pztz': '/publish/portal0/tab1362/',
|
||||
|
||||
// 国际合作局 - 进程简表 https://www.nsfc.gov.cn/publish/portal0/tab1366/
|
||||
'gjhzj-jcjb': '/publish/portal0/tab1366/',
|
||||
|
||||
// 国际合作局 - 信息公开 https://www.nsfc.gov.cn/publish/portal0/tab1386/
|
||||
'gjhzj-xxgk': '/publish/portal0/tab1386/',
|
||||
};
|
||||
@@ -29,7 +29,7 @@ module.exports = function (router) {
|
||||
router.get(/nopss(\/[\w/-]+)?/, require('./nopss'));
|
||||
router.get('/nrta/news/:category?', require('./nrta/news'));
|
||||
router.get('/nrta/dsj/:category?', require('./nrta/dsj'));
|
||||
router.get('/nsfc/news/:type?', require('./nsfc'));
|
||||
router.get(/nsfc(\/[\w-/]+)?/, require('./nsfc'));
|
||||
router.get('/pbc/goutongjiaoliu', require('./pbc/goutongjiaoliu'));
|
||||
router.get('/pbc/gzlw', require('./pbc/gzlw'));
|
||||
router.get('/pbc/tradeAnnouncement', require('./pbc/tradeAnnouncement'));
|
||||
|
||||
Reference in New Issue
Block a user