From 849cfa048e342ed277c9cac8f691665f8fa629c8 Mon Sep 17 00:00:00 2001 From: Jeason0228 <44083849+Jeason0228@users.noreply.github.com> Date: Wed, 30 Oct 2019 19:25:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20UI=E4=B8=AD=E5=9B=BD=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E4=BD=9C=E5=93=81RSS=E6=8A=A5=E9=94=99=20(#3358)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/ui-cn/user.js | 74 ++++++++++++---------------------------- 1 file changed, 21 insertions(+), 53 deletions(-) diff --git a/lib/routes/ui-cn/user.js b/lib/routes/ui-cn/user.js index 5cf0f8dcb..cf9d5205b 100644 --- a/lib/routes/ui-cn/user.js +++ b/lib/routes/ui-cn/user.js @@ -5,57 +5,25 @@ module.exports = async (ctx) => { const id = ctx.params.id; const response = await got(`https://i.ui.cn/ucenter/${id}.html`); const $ = cheerio.load(response.data); - const postList = $('#works-list li').get(); - const name = $('.user-pad .us-name .n1').text(); - const result = await Promise.all( - postList.map(async (item) => { - const title = $(item) - .find('.iInspir-title') - .find('a') - .text(); - const link = $(item) - .find('.iInspir-title') - .find('a') - .attr('href'); - const guid = link; - - const single = { - title: title, - link: link, - guid: guid, - pubDate: '', - description: '', - }; - - const description_key = 'ui-cn_description' + guid; - const description_value = await ctx.cache.get(description_key); - - const pubDate_key = 'ui-cn_pubDate' + guid; - const pubDate_value = await ctx.cache.get(pubDate_key); - - if (description_value && pubDate_value) { - single.description = description_value; - single.pubDate = pubDate_value; - } else { - const temp = await got(link); - single.description = $(temp.data) - .find('.works-cont') - .html(); - single.pubDate = new Date( - $(temp.data) - .find('.works-top') - .find('.time') - .find('em') - .text() - .replace(/更新于:/g, '') - ).toUTCString(); - - ctx.cache.set(description_key, single.description); - ctx.cache.set(pubDate_key, single.pubDate); - } - - return Promise.resolve(single); - }) - ); - ctx.state.data = { title: `${name} 的设计作品 - UI 中国`, link: `https://i.ui.cn/ucenter/${id}.html`, item: result }; + const name = $('.person_name').text(); + const intro = $('.person_intro').text(); + const response2 = await got({ + method: 'get', + url: `https://i.ui.cn/index.php/Uweb/Api/projectlst?uid=${id}&type=&size=12&page=0`, + headers: { + Referer: `https://i.ui.cn/ucenter/${id}.html`, + }, + }); + const postList = response2.data.data.list; + ctx.state.data = { + title: `${name} 的设计作品 - UI 中国`, + link: `https://i.ui.cn/ucenter/${id}.html`, + description: intro, + item: postList.map((item) => ({ + title: item.name, + description: `${item.name}
`, + link: `https://www.ui.cn/detail/${item.id}.html`, + guid: item.id, + })), + }; };