feat(route): add 时事一点通资讯 (#7462)

Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
Ethan Shen 2021-08-12 15:57:59 +08:00 committed by GitHub
parent ee66846fe1
commit fa2eebdbd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 0 deletions

View File

@ -1968,6 +1968,18 @@ column 为 third 时可选的 category:
<Route author="LogicJake" example="/who/news-room/feature-stories" path="/who/news-room/:type" :paramsDesc="['类别,可在 URL 中找到']"/>
## 时事一点通
### 资讯
<Route author="nczitzk" example="/ssydt/article" path="/ssydt/article/:id?" :paramsDesc="['id见下表默认为推荐']">
| 推荐 | 时事日报 | 时事专题 | 备考技巧 | 招考信息 | 时事月报 | 重要会议 | 领导讲话 | 时事周刊 | 官网公告 | 时事评论 |
| ---- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- |
| 0 | 3 | 6 | 13 | 12 | 4 | 10 | 11 | 5 | 8 | 7 |
</Route>
## 数英网
### 数英网最新文章

View File

@ -4158,6 +4158,9 @@ router.get('/tanchinese/:category?', require('./routes/tanchinese'));
// Harvard
router.get('/harvard/health/blog', require('./routes/universities/harvard/health/blog'));
// 时事一点通
router.get('/ssydt/article/:id?', require('./routes/ssydt/article'));
// 湖北省软件行业协会
router.get('/gov/hubei/hbsia/:caty', require('./routes/gov/hubei/hbsia'));

View File

@ -0,0 +1,59 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const titles = {
0: '推荐',
3: '时事日报',
6: '时事专题',
13: '备考技巧',
12: '招考信息',
4: '时事月报',
10: '重要会议',
11: '领导讲话',
5: '时事周刊',
8: '官网公告',
7: '时事评论',
};
module.exports = async (ctx) => {
const id = ctx.params.id || '';
const rootUrl = 'https://www.ssydt.com';
const currentUrl = `${rootUrl}/api/article/articles?product=ssydt&terminal=Browser&pageSize=20&articleTypeId=${id}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const list = response.data.results.map((item) => ({
guid: item.id,
title: item.title,
link: `${rootUrl}/article/${item.id}`,
pubDate: timezone(parseDate(item.gmtCreate), +8),
}));
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,
});
const content = cheerio.load(detailResponse.data);
item.description = content('.article-content').html();
return item;
})
)
);
ctx.state.data = {
title: `${titles[id === '' ? '0' : id]} - 时事一点通`,
link: `${rootUrl}/article?type=${id}`,
item: items,
};
};