From d5e56c14fbb42b0667d5b2663d2b3ebea6057a6f Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Thu, 13 Apr 2023 23:47:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=AD=E5=9B=BD?= =?UTF-8?q?=E6=8A=80=E6=9C=AF=E7=BB=8F=E6=B5=8E=E5=AD=A6=E4=BC=9A=20(#1230?= =?UTF-8?q?0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(deps): bump chrono-node from 2.6.2 to 2.6.3 (#513) Bumps [chrono-node](https://github.com/wanasit/chrono) from 2.6.2 to 2.6.3. - [Release notes](https://github.com/wanasit/chrono/releases) - [Commits](https://github.com/wanasit/chrono/compare/v2.6.2...v2.6.3) --- updated-dependencies: - dependency-name: chrono-node dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump meilisearch from 0.32.2 to 0.32.3 (#518) Bumps [meilisearch](https://github.com/meilisearch/meilisearch-js) from 0.32.2 to 0.32.3. - [Release notes](https://github.com/meilisearch/meilisearch-js/releases) - [Commits](https://github.com/meilisearch/meilisearch-js/compare/v0.32.2...v0.32.3) --- updated-dependencies: - dependency-name: meilisearch dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump koa from 2.14.1 to 2.14.2 (#522) Bumps [koa](https://github.com/koajs/koa) from 2.14.1 to 2.14.2. - [Release notes](https://github.com/koajs/koa/releases) - [Changelog](https://github.com/koajs/koa/blob/2.14.2/History.md) - [Commits](https://github.com/koajs/koa/compare/2.14.1...2.14.2) --- updated-dependencies: - dependency-name: koa dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat(route): add 中国技术经济学会 * style: fix linebreak --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docs/study.md | 12 +++++++++ lib/v2/cste/index.js | 56 +++++++++++++++++++++++++++++++++++++++ lib/v2/cste/maintainer.js | 3 +++ lib/v2/cste/radar.js | 13 +++++++++ lib/v2/cste/router.js | 3 +++ 5 files changed, 87 insertions(+) create mode 100644 lib/v2/cste/index.js create mode 100644 lib/v2/cste/maintainer.js create mode 100644 lib/v2/cste/radar.js create mode 100644 lib/v2/cste/router.js diff --git a/docs/study.md b/docs/study.md index e473507ee..d60809a23 100644 --- a/docs/study.md +++ b/docs/study.md @@ -679,6 +679,18 @@ path="/ctfhub/upcoming/:limit?" +## 中国技术经济学会 + +### 栏目 + + + +| 通知公告 | 学会新闻 | 科协简讯 | 学科动态 | 往事钩沉 | +| -------- | -------- | -------- | -------- | -------- | +| 16 | 18 | 19 | 20 | 21 | + + + ## 中国留学网 ### 通知公告 diff --git a/lib/v2/cste/index.js b/lib/v2/cste/index.js new file mode 100644 index 000000000..0fad40e80 --- /dev/null +++ b/lib/v2/cste/index.js @@ -0,0 +1,56 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const id = ctx.params.id ?? '16'; + const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 10; + + const rootUrl = 'https://www.cste.org.cn'; + const currentUrl = `${rootUrl}/site/term/${id}.html`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('a.list-group-item') + .slice(0, limit) + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.find('h5').text(), + link: `${rootUrl}${item.attr('href')}`, + pubDate: parseDate(item.find('small').text()), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + content('.Next').remove(); + + item.description = content('.article').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `中国技术经济学会 - ${$('.leftTop').text()}`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/cste/maintainer.js b/lib/v2/cste/maintainer.js new file mode 100644 index 000000000..77e7f46e2 --- /dev/null +++ b/lib/v2/cste/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:id?': ['nczitzk'], +}; diff --git a/lib/v2/cste/radar.js b/lib/v2/cste/radar.js new file mode 100644 index 000000000..b2f8206b7 --- /dev/null +++ b/lib/v2/cste/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'cste.org.cn': { + _name: '中国技术经济学会', + '.': [ + { + title: '栏目', + docs: 'https://docs.rsshub.app/study.html#zhong-guo-ji-shu-jing-ji-xue-hui-lan-mu', + source: ['/site/term', '/'], + target: (params, url) => `/cste/${new URL(url).match(/site\/term\/(\d+)\.html/)[1]}`, + }, + ], + }, +}; diff --git a/lib/v2/cste/router.js b/lib/v2/cste/router.js new file mode 100644 index 000000000..c7491b29f --- /dev/null +++ b/lib/v2/cste/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:id?', require('./index')); +};