diff --git a/docs/en/traditional-media.md b/docs/en/traditional-media.md index 8ee8e036db..da95d1dd9f 100644 --- a/docs/en/traditional-media.md +++ b/docs/en/traditional-media.md @@ -680,7 +680,7 @@ Provide full article RSS for WSJ topics. ### News - + `Region` | Hong Kong | Taiwan | US | diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 908ab783e3..9619b122cd 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -530,7 +530,7 @@ Solidot 提供的 feed: ### 新聞 - + `地区` diff --git a/lib/router.js b/lib/router.js index 34df373593..0ed5263511 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2315,7 +2315,7 @@ router.get('/chrome/webstore/extensions/:id', lazyloadRouteHandler('./routes/chr router.get('/rthk-news/:lang/:category', lazyloadRouteHandler('./routes/rthk-news/index')); // yahoo -router.get('/yahoo-news/:region/:category?', lazyloadRouteHandler('./routes/yahoo-news/index')); +// router.get('/yahoo-news/:region/:category?', lazyloadRouteHandler('./routes/yahoo-news/index')); // Yahoo!テレビ router.get('/yahoo-jp-tv/:query', lazyloadRouteHandler('./routes/yahoo-jp-tv/index')); diff --git a/lib/v2/yahoo/maintainer.js b/lib/v2/yahoo/maintainer.js new file mode 100644 index 0000000000..635d9e0d33 --- /dev/null +++ b/lib/v2/yahoo/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news/:region/:category?': ['KeiLongW'], +}; diff --git a/lib/routes/yahoo-news/index.js b/lib/v2/yahoo/news/index.js similarity index 68% rename from lib/routes/yahoo-news/index.js rename to lib/v2/yahoo/news/index.js index e25837c942..33cf515624 100644 --- a/lib/routes/yahoo-news/index.js +++ b/lib/v2/yahoo/news/index.js @@ -4,17 +4,17 @@ const cheerio = require('cheerio'); const { isValidHost } = require('@/utils/valid-host'); module.exports = async (ctx) => { - const region = ctx.params.region === 'en' ? '' : ctx.params.region.toLowerCase() + '.'; - if (!isValidHost(region)) { + const region = ctx.params.region === 'en' ? '' : ctx.params.region.toLowerCase(); + if (!isValidHost(region) && region !== '') { throw Error('Invalid region'); } const category = ctx.params.category ? ctx.params.category.toLowerCase() : ''; - const rssUrl = `https://${region}news.yahoo.com/rss/${category}`; + const rssUrl = `https://${region ? 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 filteredItems = feed.items.filter((item) => !item.link.includes('promotions') && new URL(item.link).hostname.match(/.*\.yahoo\.com$/)); const items = await Promise.all( filteredItems.map(async (item) => { const description = await ctx.cache.tryGet(item.link, async () => { @@ -24,10 +24,8 @@ module.exports = async (ctx) => { }); const $ = cheerio.load(response.data); - const $descriptionRoot = cheerio.load('
'); - $descriptionRoot('div.img-root').append($('article img:not(header img)')); - $descriptionRoot('div.content-root').append($('article p').removeAttr('content')); - return $descriptionRoot.html(); + $('.caas-content-byline-wrapper, .caas-xray-wrapper, .caas-header, .caas-readmore').remove(); + return $('.caas-content-wrapper').html(); }); const single = { title: item.title, @@ -35,7 +33,7 @@ module.exports = async (ctx) => { pubDate: item.pubDate, link: item.link, }; - return Promise.resolve(single); + return single; }) ); diff --git a/lib/v2/yahoo/radar.js b/lib/v2/yahoo/radar.js new file mode 100644 index 0000000000..0646aa4877 --- /dev/null +++ b/lib/v2/yahoo/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'yahoo.com': { + _name: 'Yahoo', + '.': [ + { + title: '新闻', + docs: 'https://docs.rsshub.app/traditional-media.html#yahoo', + source: ['/'], + target: '/yahoo/news/:region/:category?', + }, + ], + }, +}; diff --git a/lib/v2/yahoo/router.js b/lib/v2/yahoo/router.js new file mode 100644 index 0000000000..3b872344fb --- /dev/null +++ b/lib/v2/yahoo/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/news/:region/:category?', require('./news/index')); +};