From e95b7ccc404ad923d6f529e8c6992704d11cb541 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Fri, 8 Mar 2024 00:18:50 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=AD=E5=9B=BD?= =?UTF-8?q?=E7=A7=91=E5=AD=A6=E5=AD=A6=E4=B8=8E=E7=A7=91=E6=8A=80=E6=94=BF?= =?UTF-8?q?=E7=AD=96=E7=A0=94=E7=A9=B6=E4=BC=9A=E7=A0=94=E7=A9=B6=E4=BC=9A?= =?UTF-8?q?=E5=8A=A8=E6=80=81=20(#14687)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 中国科学学与科技政策研究会研究会动态 * fix typo * fix typo --------- --- lib/routes/casssp/maintainer.ts | 3 ++ lib/routes/casssp/news.ts | 60 ++++++++++++++++++++++++++++++ lib/routes/casssp/radar.ts | 41 ++++++++++++++++++++ lib/routes/casssp/router.ts | 3 ++ website/docs/routes/government.mdx | 10 +++++ 5 files changed, 117 insertions(+) create mode 100644 lib/routes/casssp/maintainer.ts create mode 100644 lib/routes/casssp/news.ts create mode 100644 lib/routes/casssp/radar.ts create mode 100644 lib/routes/casssp/router.ts diff --git a/lib/routes/casssp/maintainer.ts b/lib/routes/casssp/maintainer.ts new file mode 100644 index 000000000..062d245bd --- /dev/null +++ b/lib/routes/casssp/maintainer.ts @@ -0,0 +1,3 @@ +export default { + '/news/:category?': ['nczitzk'], +}; diff --git a/lib/routes/casssp/news.ts b/lib/routes/casssp/news.ts new file mode 100644 index 000000000..f0e9ff94d --- /dev/null +++ b/lib/routes/casssp/news.ts @@ -0,0 +1,60 @@ +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; + +export default async (ctx) => { + const { category = '3' } = ctx.req.param(); + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 15; + + const rootUrl = 'http://www.casssp.org.cn'; + const currentUrl = new URL(`news/${category}/`, rootUrl).href; + + const { data: response } = await got(currentUrl); + + const $ = load(response); + + let items = $('p.e_text-22.s_title a, p.e_text-18.s_title a') + .slice(0, limit) + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.text(), + link: new URL(item.prop('href'), rootUrl).href, + }; + }); + + items = await Promise.all( + items.map((item) => + cache.tryGet(item.link, async () => { + const { data: detailResponse } = await got(item.link); + + const content = load(detailResponse); + + item.description = content('div.e_richText-25, div.e_richText-3').html(); + item.pubDate = parseDate(`${content('p.e_timeFormat-15').text()}-${content('p.e_timeFormat-14').text()}-${content('p.e_timeFormat-11').text()}`); + + return item; + }) + ) + ); + + const image = $('img[la="la"]').first().prop('src'); + const icon = new URL($('link[rel="shortcut icon "]').prop('href'), rootUrl).href; + + ctx.set('data', { + item: items, + title: $('title').text(), + link: currentUrl, + description: $('meta[name="description"]').prop('content'), + language: $('html').prop('lang'), + image, + icon, + logo: icon, + subtitle: $('meta[name="keywords"]').prop('content'), + author: $('img[la="la"]').first().prop('title'), + allowEmpty: true, + }); +}; diff --git a/lib/routes/casssp/radar.ts b/lib/routes/casssp/radar.ts new file mode 100644 index 000000000..bced7747f --- /dev/null +++ b/lib/routes/casssp/radar.ts @@ -0,0 +1,41 @@ +export default { + 'casssp.org.cn': { + _name: '中国科学学与科技政策研究会', + '.': [ + { + title: '研究会动态', + docs: 'https://docs.rsshub.app/routes/government#zhong-guo-ke-xue-xue-yu-ke-ji-zheng-ce-yan-jiu-hui-yan-jiu-hui-dong-tai', + source: ['/news/:category'], + target: (params) => { + const category = params.category; + + return `/casssp/news${category ? `/${category}` : ''}`; + }, + }, + { + title: '研究会动态 - 通知公告', + docs: 'https://docs.rsshub.app/routes/government#zhong-guo-ke-xue-xue-yu-ke-ji-zheng-ce-yan-jiu-hui-yan-jiu-hui-dong-tai', + source: ['/news/3'], + target: '/casssp/news/3', + }, + { + title: '研究会动态 - 新闻动态', + docs: 'https://docs.rsshub.app/routes/government#zhong-guo-ke-xue-xue-yu-ke-ji-zheng-ce-yan-jiu-hui-yan-jiu-hui-dong-tai', + source: ['/news/2'], + target: '/casssp/news/2', + }, + { + title: '研究会动态 - 信息公开', + docs: 'https://docs.rsshub.app/routes/government#zhong-guo-ke-xue-xue-yu-ke-ji-zheng-ce-yan-jiu-hui-yan-jiu-hui-dong-tai', + source: ['/news/92'], + target: '/casssp/news/92', + }, + { + title: '研究会动态 - 时政要闻', + docs: 'https://docs.rsshub.app/routes/government#zhong-guo-ke-xue-xue-yu-ke-ji-zheng-ce-yan-jiu-hui-yan-jiu-hui-dong-tai', + source: ['/news/93'], + target: '/casssp/news/93', + }, + ], + }, +}; diff --git a/lib/routes/casssp/router.ts b/lib/routes/casssp/router.ts new file mode 100644 index 000000000..ec7c5eda5 --- /dev/null +++ b/lib/routes/casssp/router.ts @@ -0,0 +1,3 @@ +export default (router) => { + router.get('/news/:category?', './news'); +}; diff --git a/website/docs/routes/government.mdx b/website/docs/routes/government.mdx index 36f8f842a..161ce0fc7 100644 --- a/website/docs/routes/government.mdx +++ b/website/docs/routes/government.mdx @@ -1364,6 +1364,16 @@ | 新闻 | xw | +## 中国科学学与科技政策研究会 {#zhong-guo-ke-xue-xue-yu-ke-ji-zheng-ce-yan-jiu-hui} + +### 研究会动态 {#zhong-guo-ke-xue-xue-yu-ke-ji-zheng-ce-yan-jiu-hui-yan-jiu-hui-dong-tai} + + + | 通知公告 | 新闻动态 | 信息公开 | 时政要闻 | + | -------- | -------- | -------- | -------- | + | 3 | 2 | 92 | 93 | + + ## 中国民用航空局 {#zhong-guo-min-yong-hang-kong-ju} ### 公众留言 {#zhong-guo-min-yong-hang-kong-ju-gong-zhong-liu-yan}