Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add Topbook今天看什么 #7437

Merged
merged 2 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,12 @@ Provides all of the Thrillist articles with the specified tag.

</Route>

## Topbook

### 今天看什么

<Route author="nczitzk" example="/topbook/today" path="/topbook/today"/>

## TOPYS

### 分类
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
40 changes: 40 additions & 0 deletions lib/routes/topbook/today.js
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,
};
};