forked from chengxuanying/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add Topbook今天看什么 (DIYgod#7437)
- Loading branch information
Ethan Shen
authored
May 26, 2021
1 parent
d73e923
commit 832e3ff
Showing
3 changed files
with
49 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,40 @@ | ||
const got = require('@/utils/got'); | ||
|
||
module.exports = async (ctx) => { | ||
const rootUrl = 'https://topbook.cc'; | ||
const currentUrl = `${rootUrl}/webapi/content/article/24/page?start=0&limit=24`; | ||
const response = await got({ | ||
method: 'get', | ||
url: currentUrl, | ||
}); | ||
|
||
const list = response.data.data.items.map((item) => ({ | ||
title: item.title, | ||
pubDate: Date.parse(item.createTime), | ||
link: `${rootUrl}/webapi/content/article/query/${item.articleId}`, | ||
})); | ||
|
||
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, | ||
}); | ||
|
||
item.author = detailResponse.data.data.nickname; | ||
item.description = detailResponse.data.data.content; | ||
item.link = `${rootUrl}/overview?selectedArticle=${item.link.split('/query/')[1]}`; | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: '今天看点啥 - Topbook', | ||
link: `${rootUrl}/overview/24`, | ||
item: items, | ||
}; | ||
}; |