feat: add chicago tribune (#5097)
This commit is contained in:
parent
52b4d479ec
commit
d8561246d8
|
|
@ -483,6 +483,16 @@
|
|||
},
|
||||
],
|
||||
},
|
||||
'www.chicagotribune.com': {
|
||||
_name: 'Chicago Tribune',
|
||||
www: [
|
||||
{
|
||||
title: 'Chicago Tribune',
|
||||
docs: 'https://docs.rsshub.app/traditional_media.html#chicago-tribune',
|
||||
source: '/',
|
||||
},
|
||||
],
|
||||
},
|
||||
'haimaoba.com': {
|
||||
_name: '海猫吧',
|
||||
www: [
|
||||
|
|
|
|||
|
|
@ -26,6 +26,17 @@ Support major channels, refer to [BBC RSS feeds](https://www.bbc.co.uk/news/1062
|
|||
|
||||
</RouteEn>
|
||||
|
||||
## Chicago Tribune
|
||||
|
||||
### News
|
||||
|
||||
<RouteEn author="oppilate" example="/chicagotribune/nation-world" path="/chicagotribune/:category/:subcategory?" :paramsDesc="['Category','Subcategory']">
|
||||
|
||||
Generates full-text that the official feed doesn't provide.
|
||||
Refer to [Chicago Tribune's feed page](https://www.chicagotribune.com/about/ct-chicago-tribune-rss-feeds-htmlstory.html) for categories. For instance, `https://www.chicagotribune.com/arcio/rss/category/nation-world/` corresponds to `/chicagotribune/nation-world`.
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## China Dialogue
|
||||
|
||||
### Topics
|
||||
|
|
|
|||
|
|
@ -32,6 +32,17 @@ pageClass: routes
|
|||
|
||||
</Route>
|
||||
|
||||
## Chicago Tribune
|
||||
|
||||
### 新闻
|
||||
|
||||
<Route author="oppilate" example="/chicagotribune/nation-world" path="/chicagotribune/:category/:subcategory?" :paramsDesc="['目录分类','子分类']">
|
||||
|
||||
相比官方 RSS,多提供全文。
|
||||
目录分类[见其网站](https://www.chicagotribune.com/about/ct-chicago-tribune-rss-feeds-htmlstory.html)。例如,`https://www.chicagotribune.com/arcio/rss/category/nation-world/` 对应的 RSSHub 路由是 `/chicagotribune/nation-world`。由于官方源的部分路由有两级,因此这里也相应需要填写子分类。
|
||||
|
||||
</Route>
|
||||
|
||||
## e 公司
|
||||
|
||||
### 快讯
|
||||
|
|
|
|||
|
|
@ -2888,6 +2888,9 @@ router.get('/91ddcc/user/:user', require('./routes/91ddcc/user'));
|
|||
// BookwalkerTW热门新书
|
||||
router.get('/bookwalkertw/news', require('./routes/bookwalkertw/news'));
|
||||
|
||||
// Chicago Tribune
|
||||
router.get('/chicagotribune/:category/:subcategory?', require('./routes/chicagotribune/index'));
|
||||
|
||||
// Amazfit Watch Faces
|
||||
router.get('/amazfitwatchfaces/fresh/:model/:type?/:lang?', require('./routes/amazfitwatchfaces/fresh'));
|
||||
router.get('/amazfitwatchfaces/updated/:model/:type?/:lang?', require('./routes/amazfitwatchfaces/updated'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,78 @@
|
|||
const cheerio = require('cheerio');
|
||||
const parser = require('@/utils/rss-parser');
|
||||
const got = require('@/utils/got');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category;
|
||||
const subcategory = ctx.params.subcategory;
|
||||
const rssUrl = subcategory
|
||||
? `https://www.chicagotribune.com/arcio/rss/category/${category}/${subcategory}/?query=display_date:%5Bnow-2d+TO+now%5D+AND+revision.published:true&sort=display_date:desc#nt=instory-link`
|
||||
: `https://www.chicagotribune.com/arcio/rss/category/${category}/?query=display_date:%5Bnow-2d+TO+now%5D+AND+revision.published:true&sort=display_date:desc#nt=instory-link`;
|
||||
const feed = await parser.parseURL(rssUrl);
|
||||
|
||||
const items = await Promise.all(
|
||||
feed.items.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got({
|
||||
url: item.link,
|
||||
method: 'get',
|
||||
});
|
||||
const html = response.body;
|
||||
const $ = cheerio.load(html);
|
||||
const content = $('article > main > section#left');
|
||||
|
||||
const categories = $('meta[property="article:section"]')
|
||||
.attr('content')
|
||||
.split(',')
|
||||
.map((e) => e.trim())
|
||||
.filter((e) => e !== '');
|
||||
|
||||
// Disable image lazyloading
|
||||
content.find('img').each((i, e) => {
|
||||
e = $(e);
|
||||
e.attr('src', e.attr('data-src'));
|
||||
});
|
||||
|
||||
// Remove unwanted DOMs
|
||||
const unwanted_element_selectors = [
|
||||
'[data-pb-name="Recommender"]',
|
||||
'.inline-ad',
|
||||
'[data-type="newsletter-promo-card"]',
|
||||
'[data-type="interstitial_link"]',
|
||||
'[data-type="recommender"]',
|
||||
'.recommender',
|
||||
'[class*="pb-f-ads-"]',
|
||||
];
|
||||
unwanted_element_selectors.forEach((selector) => {
|
||||
content.find(selector).each((i, e) => {
|
||||
$(e).remove();
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
title: item.title.trim(),
|
||||
id: item.guid,
|
||||
pubDate: new Date(item.pubDate).toUTCString(),
|
||||
author: item.creator.trim(),
|
||||
link: item.link,
|
||||
summary: item.content.trim(),
|
||||
description: content.html(),
|
||||
category: categories,
|
||||
icon: 'https://www.chicagotribune.com/pb/resources/images/ct_icons/144-iTunesArtwork.png',
|
||||
logo: 'https://upload.wikimedia.org/wikipedia/commons/c/c4/Chicago_Tribune_Logo.svg',
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: feed.title,
|
||||
link: feed.link,
|
||||
description: feed.description,
|
||||
item: items,
|
||||
language: 'en-us',
|
||||
icon: 'https://www.chicagotribune.com/pb/resources/images/ct_icons/144-iTunesArtwork.png',
|
||||
logo: 'https://upload.wikimedia.org/wikipedia/commons/c/c4/Chicago_Tribune_Logo.svg',
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue