Files
RSSHub/lib/routes/cnbeta/home.js
2020-06-14 22:00:02 +08:00

53 lines
1.5 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const parser = require('@/utils/rss-parser');
module.exports = async (ctx) => {
const feed = await parser.parseURL('https://rss.cnbeta.com/');
const ProcessFeed = (data) => {
const $ = cheerio.load(data);
// 移除6.18广告
$('.article-global').remove();
// 提取内容
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: feed.description,
item: items,
};
};