feat: add 优设网细节猎人 (#6182)

This commit is contained in:
Ethan Shen
2020-11-16 20:32:55 +00:00
committed by GitHub
parent 10e691640b
commit f007624d2b
3 changed files with 69 additions and 0 deletions
+10
View File
@@ -122,6 +122,16 @@ Behance 用户主页 URL 获取用户名,如 <https://www.behance.net/mishapet
<Route author="MisteryMonster" example="/unit-image/films/vfx" path="/unit-image/films/:type?" :paramsDesc="['Films 下分类,`vfx`, `game-trailer`, `animation`, `commercials`, `making-of`']"/>
## 优设网
### 细节猎人
<Route author="nczitzk" example="/uisdc/topic/all" path="/uisdc/topic/:title?/:sort?" :paramsDesc="['标签名称,可在标签页的 URL 中找到', '排序方式,`hot` 指最热门,默认为最新鲜']">
更多细节标签请参见 [全部标签](https://www.uisdc.com/alltopics)
</Route>
## 站酷
### 推荐
+3
View File
@@ -3502,4 +3502,7 @@ router.get('/jiazhen108', require('./routes/jiazhen108/index'));
// Instagram
router.get('/instagram/:category/:key', require('./routes/instagram/index'));
// 优设网
router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic'));
module.exports = router;
+56
View File
@@ -0,0 +1,56 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const date = require('@/utils/date');
module.exports = async (ctx) => {
const title = ctx.params.title || 'all';
const sort = ctx.params.sort || '';
const rootUrl = 'https://www.uisdc.com';
const currentUrl = `${rootUrl}/${title === 'all' ? 'hunter' : 'topic/' + title}${sort === '' ? '' : '?od=' + sort}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('.item-left h2 a, .topic-item h2 a')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
title: item.text(),
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.author = content('h3.author').text().replace(':', '');
content('.info .author').remove();
item.description = content('span.img-zoom').html() + content('.main .info').html();
item.pubDate = date(detailResponse.data.match(/<span class="item">时间:(.*)<\/span>/)[1]);
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
};
};