diff --git a/docs/design.md b/docs/design.md index c125f2096..ac8b5f24c 100644 --- a/docs/design.md +++ b/docs/design.md @@ -122,6 +122,16 @@ Behance 用户主页 URL 获取用户名,如 +## 优设网 + +### 细节猎人 + + + +更多细节标签请参见 [全部标签](https://www.uisdc.com/alltopics) + + + ## 站酷 ### 推荐 diff --git a/lib/router.js b/lib/router.js index 16cdbc170..113514e27 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/uisdc/topic.js b/lib/routes/uisdc/topic.js new file mode 100644 index 000000000..cb94a9081 --- /dev/null +++ b/lib/routes/uisdc/topic.js @@ -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>/)[1]); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};