Skip to content

Commit

Permalink
feat(route): add CBNData消费站看点 (DIYgod#7810)
Browse files Browse the repository at this point in the history
Co-authored-by: NeverBehave <[email protected]>
  • Loading branch information
Ethan Shen and NeverBehave authored Jul 17, 2021
1 parent 3396d0a commit adcf6ea
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ pageClass: routes

<Route author="kt286" example="/bof/home" path="/bof/home" />

## CBNData

### 看点

<Route author="nczitzk" example="/cbndata/information" path="/cbndata/information/:category?" :paramsDesc="['分类,见下表,默认为看点']">

| 看点 | 餐饮零售 | 美妆个护 | 服饰鞋包 | 家电数码 | 宠物 | 营销 |
| ---- | -------- | -------- | -------- | -------- | ---- | ---- |
| | 2560 | 1 | 2559 | 59 | 2419 | 2484 |

</Route>

## cfan

### 新闻
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4130,6 +4130,9 @@ router.get('/caus/:category?', require('./routes/caus'));
// 摩点
router.get('/modian/zhongchou/:category?/:sort?/:status?', require('./routes/modian/zhongchou'));

// CBNData
router.get('/cbndata/information/:category?', require('./routes/cbndata/information'));

// TANC 艺术新闻
router.get('/tanchinese/:category?', require('./routes/tanchinese'));

Expand Down
53 changes: 53 additions & 0 deletions lib/routes/cbndata/information.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const got = require('@/utils/got');

module.exports = async (ctx) => {
const category = ctx.params.category || '';

const rootUrl = 'https://www.cbndata.com';
const apiUrl = `${rootUrl}/api/v3/informations?page=1&per_page=10${category ? `&tag_id=${category}` : ''}`;

const response = await got({
method: 'get',
url: apiUrl,
});

const list = response.data.data.map((item) => ({
title: item.id,
link: `${rootUrl}/api/v3/informations/show?id=${item.id}`,
pubDate: Date.parse(item.date),
}));

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.link = `${rootUrl}/information/${item.title}`;

item.title = detailResponse.data.data.title;
item.author = detailResponse.data.data.author;
item.description = detailResponse.data.data.content;

return item;
})
)
);

let title = '看点';

for (const tag of response.data.home_tags) {
if (tag.id.toString() === category) {
title = tag.name;
break;
}
}
ctx.state.data = {
title: `${title} - CBNData消费站`,
link: `${rootUrl}/information${category ? `?tag_id=${category}` : ''}`,
item: items,
};
};

0 comments on commit adcf6ea

Please sign in to comment.