feat(route): thehindu topic (#12964)
This commit is contained in:
parent
d1457e3ab6
commit
4e809d51fa
|
|
@ -118,7 +118,7 @@ There is no RSS source for Al Jazeera Chinese, returning homepage content by def
|
|||
|
||||
### Topics
|
||||
|
||||
<RouteEn author="zoenglinghou mjysci TonyRL" example="/apnews/topics/apf-topnews" path="/apnews/topics/:topic?" :paramsDesc="['Topic name,can be found in URL. For example: the topic name of AP Top News [https://apnews.com/apf-topnews](https://apnews.com/apf-topnews) is `apf-topnews`, `trending-news` by default']" radar="1" rssbud="1" />
|
||||
<RouteEn author="zoenglinghou mjysci TonyRL" example="/apnews/topics/apf-topnews" path="/apnews/topics/:topic?" :paramsDesc="['Topic name, can be found in URL. For example: the topic name of AP Top News [https://apnews.com/apf-topnews](https://apnews.com/apf-topnews) is `apf-topnews`, `trending-news` by default']" radar="1" rssbud="1" />
|
||||
|
||||
## BBC
|
||||
|
||||
|
|
@ -678,6 +678,12 @@ Provides a better reading experience (full text articles) over the official one.
|
|||
|
||||
<RouteEn author="Polynomia" example="/guardian/china" path="/guardian/china"/>
|
||||
|
||||
## The Hindu
|
||||
|
||||
### Topic
|
||||
|
||||
<RouteEn author="TonyRL" example="/thehindu/topic/rains" path="/thehindu/topic/:topic" :paramsDesc="['Topic slug, can be found in URL.']" radar="1" rssbud="1" />
|
||||
|
||||
## The New York Times
|
||||
|
||||
### News
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/topic/:topic': ['TonyRL'],
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'thehindu.com': {
|
||||
_name: 'The Hindu',
|
||||
'.': [
|
||||
{
|
||||
title: 'Topic',
|
||||
docs: 'https://docs.rsshub.app/en/traditional-media.html#the-hindu',
|
||||
source: ['/topic/:topic'],
|
||||
target: '/thehindu/topic/:topic',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/topic/:topic', require('./topic'));
|
||||
};
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const baseUrl = 'https://www.thehindu.com';
|
||||
const { topic } = ctx.params;
|
||||
const link = `${baseUrl}/topic/${topic}/`;
|
||||
const apiLink = `${baseUrl}/topic/${topic}/fragment/showmoreTag`;
|
||||
|
||||
const { data: response } = await got(link);
|
||||
const { data: apiResponse } = await got(apiLink);
|
||||
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
const $api = cheerio.load(apiResponse);
|
||||
const list = $('.element')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $api(item);
|
||||
const a = item.find('.title a');
|
||||
return {
|
||||
title: a.text().trim(),
|
||||
link: a.attr('href'),
|
||||
author: item.find('.author-name').text(),
|
||||
};
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
$('.position-relative, .articleblock-container, .article-ad, .comments-shares').remove();
|
||||
item.description = $('.sub-title').prop('outerHTML') + $('div.article-picture').html() + $('div[itemprop="articleBody"]').html();
|
||||
item.pubDate = parseDate($('meta[itemprop="datePublished"]').attr('content'));
|
||||
item.updated = parseDate($('meta[itemprop="dateModified"]').attr('content'));
|
||||
item.category = $('meta[property="article:tag"]')
|
||||
.toArray()
|
||||
.map((item) => $(item).attr('content'));
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('head title').text().trim(),
|
||||
link: `${baseUrl}/topic/${topic}/`,
|
||||
image: $('meta[property="og:image"]').attr('content'),
|
||||
logo: $('link[rel="apple-touch-icon"]').attr('href'),
|
||||
icon: $('link[rel="icon"]').attr('href'),
|
||||
language: 'en',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue