Skip to content

Commit

Permalink
feat(route): add 时事一点通资讯 (#7462)
Browse files Browse the repository at this point in the history
Co-authored-by: NeverBehave <[email protected]>
  • Loading branch information
Ethan Shen and NeverBehave authored Aug 12, 2021
1 parent ee66846 commit fa2eebd
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>

## 数英网

### 数英网最新文章
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
59 changes: 59 additions & 0 deletions lib/routes/ssydt/article.js
Original file line number Diff line number Diff line change
@@ -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,
};
};

1 comment on commit fa2eebd

@vercel
Copy link

@vercel vercel bot commented on fa2eebd Aug 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.