-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: NeverBehave <[email protected]>
- Loading branch information
1 parent
ee66846
commit fa2eebd
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
fa2eebd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: