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}