mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-18 13:02:42 +08:00
fix: 使用官方rss源,避免因为文章置顶和取消置顶造成的文章重复 (#2383)
This commit is contained in:
@@ -1,27 +1,59 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const util = require('./utils');
|
||||
const parser = require('@/utils/rss-parser');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: 'https://www.cnbeta.com/',
|
||||
headers: {
|
||||
Referer: 'https://www.cnbeta.com/',
|
||||
},
|
||||
});
|
||||
const feed = await parser.parseURL('https://rss.cnbeta.com/');
|
||||
|
||||
const data = response.data;
|
||||
const ProcessFeed = (data) => {
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
const $ = cheerio.load(data);
|
||||
const list = $('.items-area [id^="J_all_item_"]').get();
|
||||
// 还原图片地址
|
||||
$('img').each((index, elem) => {
|
||||
const $elem = $(elem);
|
||||
const src = $elem.attr('data-original');
|
||||
if (src && src !== '') {
|
||||
$elem.attr('src', `${src}`);
|
||||
}
|
||||
$elem.attr('referrerpolicy', 'no-referrer');
|
||||
});
|
||||
|
||||
const result = await util.ProcessFeed(list, ctx.cache);
|
||||
// 提取内容
|
||||
return $('.article-summary p').html() + '<br>' + $('.article-content').html();
|
||||
};
|
||||
|
||||
const items = await Promise.all(
|
||||
feed.items
|
||||
.filter((item) => item.author !== 'adam')
|
||||
.map(async (item) => {
|
||||
const cache = await ctx.cache.get(item.link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const description = ProcessFeed(response.data);
|
||||
|
||||
const single = {
|
||||
title: item.title,
|
||||
description,
|
||||
pubDate: item.pubDate,
|
||||
link: item.link,
|
||||
author: item.author,
|
||||
};
|
||||
ctx.cache.set(item.link, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'cnBeta',
|
||||
link: 'https://www.cnbeta.com/',
|
||||
description: $('meta[name="description"]').attr('content'),
|
||||
item: result,
|
||||
description: feed.description,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user