feat(route): tass (#14426)
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/:category?': ['TonyRL'],
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/:category?', require('./news'));
|
||||
};
|
||||
@@ -476,6 +476,16 @@ This route adds the missing photo and Link element. (Offical RSS doesn't have Li
|
||||
(`opencc` 是 RSSHub 的通用参数,详情请参阅 [「中文简繁体转换」](/parameter#中文简繁体转换))
|
||||
</Route>
|
||||
|
||||
## Russian News Agency TASS {#russian-news-agency-tass}
|
||||
|
||||
### News {#russian-news-agency-tass-news}
|
||||
|
||||
<Route author="TonyRL" example="/tass/politics" path="/tass/:category?" paramsDesc={['Category, can be found in URL, `politics` by default']} radar="1">
|
||||
| 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 |
|
||||
</Route>
|
||||
|
||||
## Solidot {#solidot}
|
||||
|
||||
### 最新消息 {#solidot-zui-xin-xiao-xi}
|
||||
|
||||
Reference in New Issue
Block a user