fix(route): gameapps next pages (#11957)
This commit is contained in:
parent
c389e2c887
commit
aefd309a3a
|
|
@ -7,28 +7,54 @@ const path = require('path');
|
|||
|
||||
module.exports = async (ctx) => {
|
||||
const baseUrl = 'https://www.gameapps.hk';
|
||||
const feed = await parser.parseURL(`https://www.gameapps.hk/rss`);
|
||||
const feed = await parser.parseURL(`${baseUrl}/rss`);
|
||||
|
||||
const items = await Promise.all(
|
||||
feed.items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got({
|
||||
url: item.link,
|
||||
const { data: response } = await got(item.link, {
|
||||
headers: {
|
||||
Referer: baseUrl,
|
||||
},
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
const nextPages = $('.pagination li')
|
||||
.not('.disabled')
|
||||
.not('.active')
|
||||
.find('a')
|
||||
.toArray()
|
||||
.map((a) => `${baseUrl}${a.attribs.href}`);
|
||||
|
||||
$('.pages').remove();
|
||||
|
||||
const content = $('.news-content');
|
||||
|
||||
// remove unwanted key value
|
||||
delete item.content;
|
||||
delete item.contentSnippet;
|
||||
delete item.isoDate;
|
||||
|
||||
if (nextPages.length) {
|
||||
const pages = await Promise.all(
|
||||
nextPages.map(async (url) => {
|
||||
const { data: response } = await got(url, {
|
||||
headers: {
|
||||
referer: item.link,
|
||||
},
|
||||
});
|
||||
const $ = cheerio.load(response);
|
||||
$('.pages').remove();
|
||||
return $('.news-content').html();
|
||||
})
|
||||
);
|
||||
content.append(pages);
|
||||
}
|
||||
|
||||
item.description = art(path.join(__dirname, 'templates/description.art'), {
|
||||
src: $('div.introduction.media.news-intro div.media-left').find('img').attr('src'),
|
||||
intro: $('div.introduction.media.news-intro div.media-body').html().trim(),
|
||||
desc: $('.news-content').html().trim(),
|
||||
desc: content.html().trim(),
|
||||
});
|
||||
item.guid = item.guid.substring(0, item.link.lastIndexOf('/'));
|
||||
item.pubDate = parseDate(item.pubDate);
|
||||
|
|
@ -42,14 +68,7 @@ module.exports = async (ctx) => {
|
|||
title: feed.title,
|
||||
link: feed.link,
|
||||
description: feed.description,
|
||||
item: items,
|
||||
language: feed.language,
|
||||
};
|
||||
|
||||
ctx.state.json = {
|
||||
title: feed.title,
|
||||
link: feed.link,
|
||||
description: feed.description,
|
||||
image: `${baseUrl}/static/favicon/apple-touch-icon.png`,
|
||||
item: items,
|
||||
language: feed.language,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue