fix pocket trending (#5221)

This commit is contained in:
hoilc 2020-07-28 12:55:12 +08:00 committed by GitHub
parent 90030ec017
commit 9dbe56b22c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 5 deletions

View File

@ -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 ? `<img src="${media}">` : '';
return {
title: item.find('.title').text(),
author: item.find('.domain > a').text(),
description: `<p>${item.find('.excerpt').text()}</p><img src="${item.find('.item_image').attr('data-thumburl')}" />`,
link: item.find('.item_link').attr('data-saveurl'),
author: item.find('.details > span').first().text(),
description: `<p>${item.find('.excerpt').text()}</p>` + pic_html,
link: middle_link.searchParams.get('url') || middle_link.href,
};
}),
};