From c1cbcc139c336151f684107eca069147a7de323c Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 20 Feb 2022 23:39:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=AD=E5=9B=BD?= =?UTF-8?q?=E6=94=B6=E5=85=A5=E5=88=86=E9=85=8D=E7=A0=94=E7=A9=B6=E9=99=A2?= =?UTF-8?q?=20(#7453)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 中国收入分配研究院 * fix typo * refactor: migrate to v2 Co-authored-by: TonyRL --- docs/new-media.md | 12 ++++++++ lib/v2/ciidbnu/index.js | 58 ++++++++++++++++++++++++++++++++++++ lib/v2/ciidbnu/maintainer.js | 3 ++ lib/v2/ciidbnu/radar.js | 13 ++++++++ lib/v2/ciidbnu/router.js | 3 ++ 5 files changed, 89 insertions(+) create mode 100644 lib/v2/ciidbnu/index.js create mode 100644 lib/v2/ciidbnu/maintainer.js create mode 100644 lib/v2/ciidbnu/radar.js create mode 100644 lib/v2/ciidbnu/router.js diff --git a/docs/new-media.md b/docs/new-media.md index 19403c17c..a9d878f8d 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -3645,6 +3645,18 @@ column 为 third 时可选的 category: +## 中国收入分配研究院 + +### 分类 + + + +| 社会动态 | 院内新闻 | 学术观点 | 文献书籍 | 工作论文 | 专题讨论 | +| -------- | -------- | -------- | -------- | -------- | -------- | +| 1 | 5 | 3 | 4 | 6 | 8 | + + + ## 中国橡胶网 ### 新闻资讯 diff --git a/lib/v2/ciidbnu/index.js b/lib/v2/ciidbnu/index.js new file mode 100644 index 000000000..e1481c295 --- /dev/null +++ b/lib/v2/ciidbnu/index.js @@ -0,0 +1,58 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const iconv = require('iconv-lite'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +module.exports = async (ctx) => { + const id = ctx.params.id ?? '1'; + + const rootUrl = 'http://www.ciidbnu.org'; + const currentUrl = `${rootUrl}/new1.asp?pagetype=${id}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('#newsrightlist a') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: `${rootUrl}${item.attr('href').replace('..', '')}`, + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await 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').html(); + item.pubDate = timezone(parseDate(content('.t8').eq(0).text(), 'YYYY/M/D H:mm:ss'), +8); + + content('.t14').remove(); + + item.author = content('#author').text(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${$('h3').text()} - 中国收入分配研究院`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/ciidbnu/maintainer.js b/lib/v2/ciidbnu/maintainer.js new file mode 100644 index 000000000..77e7f46e2 --- /dev/null +++ b/lib/v2/ciidbnu/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:id?': ['nczitzk'], +}; diff --git a/lib/v2/ciidbnu/radar.js b/lib/v2/ciidbnu/radar.js new file mode 100644 index 000000000..bada45844 --- /dev/null +++ b/lib/v2/ciidbnu/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'ciidbnu.org': { + _name: '中国收入分配研究院', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/new-media.html#', + source: ['/new1.asp', '/'], + target: (_params, url) => `/ciidbnu/${new URL(url).searchParams.get('pagetype')}`, + }, + ], + }, +}; diff --git a/lib/v2/ciidbnu/router.js b/lib/v2/ciidbnu/router.js new file mode 100644 index 000000000..2353c905f --- /dev/null +++ b/lib/v2/ciidbnu/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:id?', require('./index')); +};