fix(route): 修复机核网资讯 (#11412)

* fix(route): gcores/news

* fix(route): gcores/category/news
This commit is contained in:
StevenRCE0 2022-12-08 19:37:32 +08:00 committed by GitHub
parent 7fd8dcf326
commit 97b651e924
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 6 deletions

View File

@ -12,16 +12,26 @@ module.exports = async (ctx) => {
const $ = cheerio.load(data);
const feedTitle = $('title').text();
const list = $('.original.am_card.original-normal')
.map(function () {
let list;
if (category === 'news') {
list = $('a.news').map(function () {
const item = {
url: $(this).attr('href'),
title: $(this).find('.news_content>h3').text(),
};
return item;
});
} else {
list = $('.original.am_card.original-normal').map(function () {
const item = {
url: $(this).find('.am_card_inner>a').attr('href'),
title: $(this).find('h3.am_card_title').text(),
category: $(this).find('span.original_category>a').text(),
};
return item;
})
.get();
});
}
list = list.get();
if (list.length > 0 && list.every((item) => item.url === undefined)) {
throw new Error('Article URL not found! Please submit an issue on GitHub.');
@ -85,13 +95,13 @@ module.exports = async (ctx) => {
$('.story_hidden').replaceWith('');
const content = $('.story.story-show').html();
return {
const basicItem = {
title: item.title,
description: cover + content,
category: item.category,
link: articleUrl,
guid: articleUrl,
};
return category === 'news' ? basicItem : { ...basicItem, category: item.category };
});
})
);