mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 23:00:48 +08:00
feat: Add Yahoo news (#3720)
This commit is contained in:
@@ -81,3 +81,21 @@ Provides a better reading experience (full text articles) over the official one.
|
|||||||
| (空) | dual | en | dual-traditionalchinese | traditionalchinese |
|
| (空) | dual | en | dual-traditionalchinese | traditionalchinese |
|
||||||
|
|
||||||
</RouteEn>
|
</RouteEn>
|
||||||
|
|
||||||
|
## Yahoo
|
||||||
|
|
||||||
|
### News
|
||||||
|
|
||||||
|
<Route author="KeiLongW" example="/yahoo-news/hk/world" path="/yahoo-news/:region/:category?" :paramsDesc="['Region','Category']">
|
||||||
|
|
||||||
|
`Region`
|
||||||
|
| Hong Kong | Taiwan | US |
|
||||||
|
| -- | -- | -- |
|
||||||
|
| hk | tw | en |
|
||||||
|
|
||||||
|
`Category`
|
||||||
|
| All | World | Business | Entertainment | Sports | Health |
|
||||||
|
| -- | -- | -- | -- | -- | -- |
|
||||||
|
| (Empty) | world | business | entertainment | sports | health |
|
||||||
|
|
||||||
|
</Route>
|
||||||
|
|||||||
@@ -96,6 +96,24 @@ Solidot 提供的 feed:
|
|||||||
|
|
||||||
<Route author="xyqfer" example="/the-economist/gre-vocabulary" path="/the-economist/gre-vocabulary" />
|
<Route author="xyqfer" example="/the-economist/gre-vocabulary" path="/the-economist/gre-vocabulary" />
|
||||||
|
|
||||||
|
## Yahoo
|
||||||
|
|
||||||
|
### 新聞
|
||||||
|
|
||||||
|
<Route author="KeiLongW" example="/yahoo-news/hk/world" path="/yahoo-news/:region/:category?" :paramsDesc="['地区','类别']">
|
||||||
|
|
||||||
|
`地区`
|
||||||
|
| 香港 | 台灣 | 美國 |
|
||||||
|
| -- | -- | -- |
|
||||||
|
| hk | tw | en |
|
||||||
|
|
||||||
|
`类別`
|
||||||
|
| 新聞總集 | 兩岸國際 | 財經 | 娛樂 | 體育 | 健康 |
|
||||||
|
| -- | -- | -- | -- | -- | -- |
|
||||||
|
| (空) | world | business | entertainment | sports | health |
|
||||||
|
|
||||||
|
</Route>
|
||||||
|
|
||||||
## 半月谈
|
## 半月谈
|
||||||
|
|
||||||
### 板块
|
### 板块
|
||||||
|
|||||||
@@ -2101,6 +2101,9 @@ router.get('/mlog-club/projects', require('./routes/mlog-club/projects'));
|
|||||||
// Chrome 网上应用店
|
// Chrome 网上应用店
|
||||||
router.get('/chrome/webstore/extensions/:id', require('./routes/chrome/extensions'));
|
router.get('/chrome/webstore/extensions/:id', require('./routes/chrome/extensions'));
|
||||||
|
|
||||||
|
// yahoo
|
||||||
|
router.get('/yahoo-news/:region/:category?', require('./routes/yahoo-news/index'));
|
||||||
|
|
||||||
// 白鲸出海
|
// 白鲸出海
|
||||||
router.get('/baijing', require('./routes/baijing'));
|
router.get('/baijing', require('./routes/baijing'));
|
||||||
|
|
||||||
|
|||||||
44
lib/routes/yahoo-news/index.js
vendored
Executable file
44
lib/routes/yahoo-news/index.js
vendored
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const parser = require('@/utils/rss-parser');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const region = ctx.params.region === 'en' ? '' : ctx.params.region.toLowerCase() + '.';
|
||||||
|
const category = ctx.params.category ? ctx.params.category.toLowerCase() : '';
|
||||||
|
const rssUrl = `https://${region}news.yahoo.com/rss/${category}`;
|
||||||
|
const feed = await parser.parseURL(rssUrl);
|
||||||
|
const title = feed.title;
|
||||||
|
const link = feed.link;
|
||||||
|
const description = feed.description;
|
||||||
|
const filteredItems = feed.items.filter((item) => !item.link.includes('promotions') && item.link.includes('yahoo.com'));
|
||||||
|
const items = await Promise.all(
|
||||||
|
filteredItems.map(async (item) => {
|
||||||
|
const description = await ctx.cache.tryGet(item.link, async () => {
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: item.link,
|
||||||
|
});
|
||||||
|
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
const $descriptionRoot = cheerio.load('<div><div class="img-root"></div><div class="content-root"></div></div>');
|
||||||
|
$descriptionRoot('div.img-root').append($('article img'));
|
||||||
|
$descriptionRoot('div.content-root').append($('article p').removeAttr('content'));
|
||||||
|
return $descriptionRoot.html();
|
||||||
|
});
|
||||||
|
const single = {
|
||||||
|
title: item.title,
|
||||||
|
description,
|
||||||
|
pubDate: item.pubDate,
|
||||||
|
link: item.link,
|
||||||
|
};
|
||||||
|
return Promise.resolve(single);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title,
|
||||||
|
link,
|
||||||
|
description,
|
||||||
|
item: items,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user