feat(route): add 时事一点通资讯 (#7462)
Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
parent
ee66846fe1
commit
fa2eebdbd3
|
|
@ -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>
|
||||
|
||||
## 数英网
|
||||
|
||||
### 数英网最新文章
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue