From ea32d46ba9c8e17d8f8448f7929acdb61adc8a72 Mon Sep 17 00:00:00 2001
From: Ethan Shen <42264778+nczitzk@users.noreply.github.com>
Date: Mon, 5 Sep 2022 22:39:23 +0800
Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=85=A8=E5=9B=BD?=
=?UTF-8?q?=E5=93=B2=E5=AD=A6=E7=A4=BE=E4=BC=9A=E7=A7=91=E5=AD=A6=E5=B7=A5?=
=?UTF-8?q?=E4=BD=9C=E5=8A=9E=E5=85=AC=E5=AE=A4=20(#10704)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(route): add 全国哲学社会科学工作办公室
* add radar
---
docs/government.md | 16 +++++++++++
lib/v2/gov/maintainer.js | 1 +
lib/v2/gov/nopss/index.js | 57 +++++++++++++++++++++++++++++++++++++++
lib/v2/gov/radar.js | 11 ++++++++
lib/v2/gov/router.js | 1 +
5 files changed, 86 insertions(+)
create mode 100644 lib/v2/gov/nopss/index.js
diff --git a/docs/government.md b/docs/government.md
index 6675a51899..a2b1132b62 100644
--- a/docs/government.md
+++ b/docs/government.md
@@ -408,6 +408,22 @@ pageClass: routes
+## 全国哲学社会科学工作办公室
+
+### 通用
+
+
+
+::: tip 提示
+
+路径处填写对应页面 URL 中 `http://www.nopss.gov.cn/` 后的字段。下面是一个例子。
+
+若订阅 [年度项目、青年项目和西部项目](http://www.nopss.gov.cn/GB/219469/431027) 则将对应页面 URL 中 `http://www.nopss.gov.cn/` 后的字段 `GB/219469/431027` 作为路径填入。此时路由为 [`/gov/nopss/GB/219469/431027`](https://rsshub.app/gov/nopss/GB/219469/431027)
+
+:::
+
+
+
## 泉州市跨境电子商务协会
### 新闻动态
diff --git a/lib/v2/gov/maintainer.js b/lib/v2/gov/maintainer.js
index 3ec630e6ff..55d9cfc50a 100644
--- a/lib/v2/gov/maintainer.js
+++ b/lib/v2/gov/maintainer.js
@@ -26,6 +26,7 @@ module.exports = {
'/moj/aac/news/:type?': ['TonyRL'],
'/nifdc/:path+': ['nczitzk'],
'/nmpa/:path+': ['TonyRL'],
+ '/nopss/:path+': ['nczitzk'],
'/nrta/news/:category?': ['yuxinliu-alex'],
'/nsfc/news/:type?': ['Derekmini', 'nczitzk'],
'/pbc/goutongjiaoliu': ['nczitzk'],
diff --git a/lib/v2/gov/nopss/index.js b/lib/v2/gov/nopss/index.js
new file mode 100644
index 0000000000..4c6326db50
--- /dev/null
+++ b/lib/v2/gov/nopss/index.js
@@ -0,0 +1,57 @@
+const got = require('@/utils/got');
+const cheerio = require('cheerio');
+const iconv = require('iconv-lite');
+const timezone = require('@/utils/timezone');
+const { parseDate } = require('@/utils/parse-date');
+
+module.exports = async (ctx) => {
+ const params = ctx.path === '/nopss' ? '/GB/219469' : ctx.path.replace(/^\/nopss/, '');
+
+ const rootUrl = 'http://www.nopss.gov.cn';
+ const currentUrl = `${rootUrl}${params}`;
+
+ const response = await got({
+ method: 'get',
+ url: currentUrl,
+ responseType: 'buffer',
+ });
+
+ const $ = cheerio.load(iconv.decode(response.data, 'gbk'));
+
+ let items = $('.p2j_list_con .clearfix li a')
+ .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 40)
+ .toArray()
+ .map((item) => {
+ item = $(item);
+
+ return {
+ title: item.text(),
+ link: `${rootUrl}${item.attr('href')}`,
+ pubDate: timezone(parseDate(item.next().text(), '[YYYY-MM-DD HH:mm]'), +8),
+ };
+ });
+
+ items = await Promise.all(
+ items.map((item) =>
+ ctx.cache.tryGet(item.link, async () => {
+ const detailResponse = await got({
+ method: 'get',
+ url: item.link,
+ responseType: 'buffer',
+ });
+
+ const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk'));
+
+ item.description = content('.text_con').html();
+
+ return item;
+ })
+ )
+ );
+
+ ctx.state.data = {
+ title: $('title').text(),
+ link: currentUrl,
+ item: items,
+ };
+};
diff --git a/lib/v2/gov/radar.js b/lib/v2/gov/radar.js
index 5a2f9b3437..b1ba182713 100644
--- a/lib/v2/gov/radar.js
+++ b/lib/v2/gov/radar.js
@@ -570,6 +570,17 @@ module.exports = {
},
],
},
+ 'nopss.gov.cn': {
+ _name: '全国哲学社会科学工作办公室',
+ '.': [
+ {
+ title: '通用',
+ docs: 'https://docs.rsshub.app/government.html#quan-guo-zhe-xue-she-hui-ke-xue-gong-zuo-ban-gong-shi',
+ source: ['/*path'],
+ target: (params) => `/gov/nopss/${params.path.replace('/index.html', '')}`,
+ },
+ ],
+ },
'nrta.gov.cn': {
_name: '国家广播电视总局',
'.': [
diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js
index 12395f547d..dae07bdc8c 100644
--- a/lib/v2/gov/router.js
+++ b/lib/v2/gov/router.js
@@ -18,6 +18,7 @@ module.exports = function (router) {
router.get('/moj/aac/news/:type?', require('./moj/aac/news'));
router.get(/nifdc\/([\w/-]+)?/, require('./nifdc'));
router.get(/\/nmpa\/([\w][\w/]+)?/, require('./nmpa/generic'));
+ router.get(/nopss(\/[\w/-]+)?/, require('./nopss'));
router.get('/nrta/news/:category?', require('./nrta/news'));
router.get('/nsfc/news/:type?', require('./nsfc'));
router.get('/pbc/goutongjiaoliu', require('./pbc/goutongjiaoliu'));