feat(route): add 中国科学学与科技政策研究会研究会动态 (#14687)

* feat(route): add 中国科学学与科技政策研究会研究会动态

* fix typo

* fix typo

---------
This commit is contained in:
Ethan Shen 2024-03-08 00:18:50 +08:00 committed by GitHub
parent 9445b1f478
commit e95b7ccc40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 117 additions and 0 deletions

View File

@ -0,0 +1,3 @@
export default {
'/news/:category?': ['nczitzk'],
};

60
lib/routes/casssp/news.ts Normal file
View File

@ -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,
});
};

View File

@ -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',
},
],
},
};

View File

@ -0,0 +1,3 @@
export default (router) => {
router.get('/news/:category?', './news');
};

View File

@ -1364,6 +1364,16 @@
| 新闻 | xw |
</Route>
## 中国科学学与科技政策研究会 {#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}
<Route author="nczitzk" example="/casssp/news/3" path="/casssp/news/:category?" paramsDesc={['分类,见下表,默认为通知公告']} radar="1">
| 通知公告 | 新闻动态 | 信息公开 | 时政要闻 |
| -------- | -------- | -------- | -------- |
| 3 | 2 | 92 | 93 |
</Route>
## 中国民用航空局 {#zhong-guo-min-yong-hang-kong-ju}
### 公众留言 {#zhong-guo-min-yong-hang-kong-ju-gong-zhong-liu-yan}