From 62c8a45d1b7f526dad40454797257373de3f1330 Mon Sep 17 00:00:00 2001 From: black-desk <814727823@qq.com> Date: Sun, 28 Jun 2020 11:15:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B8=B8=E7=A0=94=E7=A4=BE=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=8A=93=E5=8F=96=E6=AD=A3=E6=96=87=20(#5046)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/yystv/category.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/routes/yystv/category.js b/lib/routes/yystv/category.js index ef48c0de2..67ce52195 100644 --- a/lib/routes/yystv/category.js +++ b/lib/routes/yystv/category.js @@ -39,9 +39,27 @@ module.exports = async (ctx) => { }) .get(); - ctx.state.data = { - title: '游研社-' + $('title').text(), - link: 'http://www.yystv.cn/b/recommend', - item: first_part.concat(second_part), - }; + const items = first_part.concat(second_part); + function getDescription(items) { + return Promise.all( + items.map(async function (currentValue) { + currentValue.description = await ctx.cache.tryGet(currentValue.link, async () => { + const r = await got({ + url: currentValue.link, + method: 'get', + }); + const $ = cheerio.load(r.data); + return $('.doc-content div').html(); + }); + return currentValue; + }) + ); + } + await getDescription(items).then(function () { + ctx.state.data = { + title: '游研社-' + $('title').text(), + link: `http://www.yystv.cn/b/${category}`, + item: items, + }; + }); };