diff --git a/docs/new-media.md b/docs/new-media.md index 2d053968618a2e..69ef5856a098bd 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -599,6 +599,12 @@ Provides all of the Thrillist articles with the specified tag. +## Topbook + +### 今天看什么 + + + ## TOPYS ### 分类 diff --git a/lib/router.js b/lib/router.js index 6f11e24cddc26c..dd3156f9c99329 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4072,6 +4072,9 @@ router.get('/jisilu/topic/:user', require('./routes/jisilu/topic')); // Constitutional Court of Baden-Württemberg (Germany) router.get('/verfghbw/press/:keyword?', require('./routes/verfghbw/press')); +// Topbook +router.get('/topbook/today', require('./routes/topbook/today')); + // Melon router.get('/melon/chart/:category?', require('./routes/melon/chart')); diff --git a/lib/routes/topbook/today.js b/lib/routes/topbook/today.js new file mode 100644 index 00000000000000..10a805753d4b1b --- /dev/null +++ b/lib/routes/topbook/today.js @@ -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, + }; +};