mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-25 10:14:31 +08:00
feat: add CBC (#5179)
This commit is contained in:
@@ -37,6 +37,12 @@ Refer to [Boston.com's feed page](https://www.boston.com/rss-feeds) for tags. Fo
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## CBC
|
||||
|
||||
Provide full article RSS for CBC topics.
|
||||
|
||||
<RouteEn author="wangbin" example="/cbc/topics" path="/cbc/topics/:topic?" :paramsDesc="['CBC topics. Default to Top Stories. For second level topics like canada/toronto, need to replace `/` by `-`.']"/>
|
||||
|
||||
## Chicago Tribune
|
||||
|
||||
### News
|
||||
|
||||
@@ -43,6 +43,12 @@ pageClass: routes
|
||||
|
||||
</Route>
|
||||
|
||||
## CBC
|
||||
|
||||
通过提取文章全文,以提供比官方源更佳的阅读体验。
|
||||
|
||||
<Route author="wangbin" example="/cbc/topics" path="/cbc/topics/:topic?" :paramsDesc="['CBC 频道。默认为 Top Stories。二级话题如 canada/toronto,需要用 `-` 替换掉 `/`。']"/>
|
||||
|
||||
## Chicago Tribune
|
||||
|
||||
### 新闻
|
||||
|
||||
@@ -2363,6 +2363,9 @@ router.get('/gbcc/trust', require('./routes/gbcc/trust'));
|
||||
// Associated Press
|
||||
router.get('/apnews/topics/:topic', require('./routes/apnews/topics'));
|
||||
|
||||
// CBC
|
||||
router.get('/cbc/topics/:topic?', require('./routes/cbc/topics'));
|
||||
|
||||
// discuz
|
||||
router.get('/discuz/:ver([7|x])/:cid([0-9]{2})/:link(.*)', require('./routes/discuz/discuz'));
|
||||
router.get('/discuz/:ver([7|x])/:link(.*)', require('./routes/discuz/discuz'));
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const baseUrl = 'https://www.cbc.ca';
|
||||
const topic = ctx.params.topic || '';
|
||||
const url = `${baseUrl}/news/${topic.replace('-', '/')}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: url,
|
||||
});
|
||||
|
||||
const data = response.data;
|
||||
|
||||
const $ = cheerio.load(data);
|
||||
const links = [];
|
||||
|
||||
function pushLinks(index, item) {
|
||||
const link = item.attribs.href;
|
||||
if (link.startsWith('/')) {
|
||||
links.push(baseUrl + link);
|
||||
}
|
||||
}
|
||||
|
||||
$('a.contentWrapper').each(pushLinks);
|
||||
$('a.card').each(pushLinks);
|
||||
|
||||
const out = await Promise.all(
|
||||
links.map(async (link) => {
|
||||
const [title, author, pubDate, description] = await ctx.cache.tryGet(link, async () => {
|
||||
const result = await got.get(link);
|
||||
|
||||
const $ = cheerio.load(result.data);
|
||||
|
||||
const head = JSON.parse($('script[type="application/ld+json"]').html());
|
||||
if (!head) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const title = head.headline;
|
||||
let author = '';
|
||||
if (head.author) {
|
||||
author = head.author.map((author) => author.name).join(' & ');
|
||||
}
|
||||
const pubDate = head.datePublished;
|
||||
const description = $('div.storyWrapper').html();
|
||||
|
||||
return [title, author, pubDate, description];
|
||||
});
|
||||
|
||||
if (!title) {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
const item = {
|
||||
title: title,
|
||||
description: description,
|
||||
pubDate: pubDate,
|
||||
link: link,
|
||||
author: author,
|
||||
};
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: url,
|
||||
item: out.filter((x) => x),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user