Skip to content

Commit

Permalink
feat: add 优设网行业新闻 (DIYgod#6200)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Shen authored Nov 24, 2020
1 parent d16439e commit a32f318
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ Behance 用户主页 URL 获取用户名,如 <https://www.behance.net/mishapet

</Route>

### 行业新闻

<Route author="nczitzk" example="/uisdc/hangye" path="/uisdc/hangye/:caty?" :paramsDesc="['分类,见下表,默认为全部新闻']">

| 全部新闻 | 活动赛事 | 品牌资讯 | 新品推荐 |
| -------- | --------------- | ---------- | ------------ |
| | events-activity | brand-news | new-products |

</Route>

### 优设读报

<Route author="nczitzk" example="/uisdc/news" path="/uisdc/news"/>
Expand Down
1 change: 1 addition & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3503,6 +3503,7 @@ router.get('/jiazhen108', require('./routes/jiazhen108/index'));
router.get('/instagram/:category/:key', require('./routes/instagram/index'));

// 优设网
router.get('/uisdc/hangye/:caty?', require('./routes/uisdc/hangye'));
router.get('/uisdc/news', require('./routes/uisdc/news'));
router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt'));
router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic'));
Expand Down
50 changes: 50 additions & 0 deletions lib/routes/uisdc/hangye.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');

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

const rootUrl = 'https://www.uisdc.com';
const currentUrl = `${rootUrl}/category/hangye${caty === '' ? '' : '/' + caty}`;
const response = await got({
method: 'get',
url: currentUrl,
});

const $ = cheerio.load(response.data);

const list = $('.item-div a')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
link: item.attr('href'),
};
})
.get();

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.title = content('#post_title').text();
item.description = content('.article').html();
item.pubDate = new Date(content('.time').attr('title')).toUTCString();

return item;
})
)
);

ctx.state.data = {
title: `${$('.current').text()} - 优设网 - UISDC`,
link: currentUrl,
item: items,
};
};

0 comments on commit a32f318

Please sign in to comment.