From fa2eebdbd355fa8e77da27637d3aedc6e7bfd21a Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Thu, 12 Aug 2021 15:57:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=97=B6=E4=BA=8B?= =?UTF-8?q?=E4=B8=80=E7=82=B9=E9=80=9A=E8=B5=84=E8=AE=AF=20(#7462)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: NeverBehave --- docs/new-media.md | 12 ++++++++ lib/router.js | 3 ++ lib/routes/ssydt/article.js | 59 +++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 lib/routes/ssydt/article.js diff --git a/docs/new-media.md b/docs/new-media.md index 588e2d510..0e8d69378 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1968,6 +1968,18 @@ column 为 third 时可选的 category: +## 时事一点通 + +### 资讯 + + + +| 推荐 | 时事日报 | 时事专题 | 备考技巧 | 招考信息 | 时事月报 | 重要会议 | 领导讲话 | 时事周刊 | 官网公告 | 时事评论 | +| ---- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | +| 0 | 3 | 6 | 13 | 12 | 4 | 10 | 11 | 5 | 8 | 7 | + + + ## 数英网 ### 数英网最新文章 diff --git a/lib/router.js b/lib/router.js index f24834255..1c6d52792 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/ssydt/article.js b/lib/routes/ssydt/article.js new file mode 100644 index 000000000..23b0be8c7 --- /dev/null +++ b/lib/routes/ssydt/article.js @@ -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, + }; +};