mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-06 05:03:44 +08:00
feat: add sixthtone news (#2404)
This commit is contained in:
@@ -189,6 +189,12 @@ pageClass: routes
|
|||||||
|
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
|
## sixthtone
|
||||||
|
|
||||||
|
### 最新文章
|
||||||
|
|
||||||
|
<Route author="kt286" example="/sixthtone/news" path="/sixthtone/news"/>
|
||||||
|
|
||||||
## The Verge
|
## The Verge
|
||||||
|
|
||||||
### The Verge
|
### The Verge
|
||||||
|
|||||||
@@ -1415,4 +1415,7 @@ router.get('/kkj/news', require('./routes/kkj/news'));
|
|||||||
// Outage.Report
|
// Outage.Report
|
||||||
router.get('/outagereport/:name/:count?', require('./routes/outagereport/service'));
|
router.get('/outagereport/:name/:count?', require('./routes/outagereport/service'));
|
||||||
|
|
||||||
|
// sixthtone
|
||||||
|
router.get('/sixthtone/news', require('./routes/sixthtone/news'));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
57
lib/routes/sixthtone/news.js
Normal file
57
lib/routes/sixthtone/news.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
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://www.sixthtone.com/rss');
|
||||||
|
|
||||||
|
const ProcessFeed = (data) => {
|
||||||
|
const $ = cheerio.load(data);
|
||||||
|
|
||||||
|
$('img').each((index, elem) => {
|
||||||
|
const $elem = $(elem);
|
||||||
|
$elem.attr('referrerpolicy', 'no-referrer');
|
||||||
|
});
|
||||||
|
|
||||||
|
// 移除广告等内容
|
||||||
|
$('[class*="advertise-"]').remove();
|
||||||
|
|
||||||
|
// 提取内容
|
||||||
|
return $('.content').html();
|
||||||
|
};
|
||||||
|
|
||||||
|
const items = await Promise.all(
|
||||||
|
feed.items.map(async (item) => {
|
||||||
|
const link = 'https:' + item.link.match(/\/\/www.sixthtone.com\/news\/\d+\//g)[0];
|
||||||
|
|
||||||
|
const cache = await ctx.cache.get(link);
|
||||||
|
if (cache) {
|
||||||
|
return Promise.resolve(JSON.parse(cache));
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: link,
|
||||||
|
});
|
||||||
|
|
||||||
|
const description = ProcessFeed(response.data);
|
||||||
|
|
||||||
|
const single = {
|
||||||
|
title: item.title,
|
||||||
|
description,
|
||||||
|
pubDate: item.pubDate,
|
||||||
|
link: link,
|
||||||
|
author: item.author,
|
||||||
|
};
|
||||||
|
ctx.cache.set(link, JSON.stringify(single));
|
||||||
|
return Promise.resolve(single);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: feed.title,
|
||||||
|
link: feed.link,
|
||||||
|
description: feed.description,
|
||||||
|
item: items,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user