diff --git a/lib/v2/tass/maintainer.js b/lib/v2/tass/maintainer.js new file mode 100644 index 00000000000000..9644afe025ca72 --- /dev/null +++ b/lib/v2/tass/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:category?': ['TonyRL'], +}; diff --git a/lib/v2/tass/news.js b/lib/v2/tass/news.js new file mode 100644 index 00000000000000..443ad117d21da1 --- /dev/null +++ b/lib/v2/tass/news.js @@ -0,0 +1,58 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const { category = 'politics' } = ctx.params; + + const { data: categoryPage, url: link } = await got(`https://tass.com/${category}`); + const $ = cheerio.load(categoryPage); + + const sectionId = $('.container .section-page') + .attr('ng-init') + .match(/sectionId\s*=\s*(\d+?);/); + + const { data: response } = await got.post('https://tass.com/userApi/categoryNewsList', { + json: { + sectionId: sectionId[1], + limit: 20, + type: 'all', + }, + }); + + const list = response.newsList.map((item) => ({ + title: item.title, + description: item.lead, + link: `https://tass.com${item.link}`, + pubDate: parseDate(item.date, 'X'), + })); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + const $ = cheerio.load(response); + + $('.news-media img').each((_, ele) => { + if (ele.attribs.src) { + ele.attribs.src = ele.attribs.src.replaceAll('/width/1020_b9261fa1', ''); + } + }); + + item.description = $('.news-header__lead').prop('outerHTML') + ($('.news-media').prop('outerHTML') ?? '') + $('.text-block').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text(), + link, + language: 'en', + image: $('head meta[property="og:image"]').attr('content'), + icon: $('head link[rel="apple-touch-icon"]').attr('href'), + logo: $('head link[rel="apple-touch-icon"]').attr('href'), + item: items, + }; +}; diff --git a/lib/v2/tass/radar.js b/lib/v2/tass/radar.js new file mode 100644 index 00000000000000..4e3f016b1c919d --- /dev/null +++ b/lib/v2/tass/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'tass.com': { + _name: 'Russian News Agency TASS', + '.': [ + { + title: 'News', + docs: 'https://docs.rsshub.app/routes/traditional-media.html#russian-news-agency-tass', + source: ['/:category'], + target: '/tass/:category', + }, + ], + }, +}; diff --git a/lib/v2/tass/router.js b/lib/v2/tass/router.js new file mode 100644 index 00000000000000..c44c1d758a44a7 --- /dev/null +++ b/lib/v2/tass/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:category?', require('./news')); +}; diff --git a/website/docs/routes/traditional-media.mdx b/website/docs/routes/traditional-media.mdx index 33e96144eb449b..3074c61ae9a8ce 100644 --- a/website/docs/routes/traditional-media.mdx +++ b/website/docs/routes/traditional-media.mdx @@ -476,6 +476,16 @@ This route adds the missing photo and Link element. (Offical RSS doesn't have Li (`opencc` 是 RSSHub 的通用参数,详情请参阅 [「中文简繁体转换」](/parameter#中文简繁体转换)) +## Russian News Agency TASS {#russian-news-agency-tass} + +### News {#russian-news-agency-tass-news} + + + | Russian Politics & Diplomacy | World | Business & Economy | Military & Defense | Science & Space | Emergencies | Society & Culture | Press Review | Sports | + | ---------------------------- | ----- | ------------------ | ------------------ | --------------- | ----------- | ----------------- | ------------ | ------ | + | politics | world | economy | defense | science | emergencies | society | pressreview | sports | + + ## Solidot {#solidot} ### 最新消息 {#solidot-zui-xin-xiao-xi}