From 9dbe56b22ccf8cf01725e4d24931842d2ee3fbf9 Mon Sep 17 00:00:00 2001 From: hoilc Date: Tue, 28 Jul 2020 12:55:12 +0800 Subject: [PATCH] fix pocket trending (#5221) --- lib/routes/pocket/trending.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/routes/pocket/trending.js b/lib/routes/pocket/trending.js index 83736c9eb..c03c69fc8 100644 --- a/lib/routes/pocket/trending.js +++ b/lib/routes/pocket/trending.js @@ -7,19 +7,24 @@ module.exports = async (ctx) => { const response = await got.get(url); const $ = cheerio.load(response.data); - const list = $('.item').toArray(); - + const list = $('article').get(); ctx.state.data = { title: 'Trending on Pocket', description: 'Top Articles and Videos about Trending on Pocket', link: url, item: list.map((item) => { item = $(item); + const middle_link = new URL(item.find('a').first().attr('href')); + const media = item + .find('.media') + .attr('style') + .match(/url\('(.*?)'\);/)[1]; + const pic_html = media ? `` : ''; return { title: item.find('.title').text(), - author: item.find('.domain > a').text(), - description: `

${item.find('.excerpt').text()}

`, - link: item.find('.item_link').attr('data-saveurl'), + author: item.find('.details > span').first().text(), + description: `

${item.find('.excerpt').text()}

` + pic_html, + link: middle_link.searchParams.get('url') || middle_link.href, }; }), };