fix(route/cbc): Fix article content html tag (#13325)
* fix(route/cbc): Fix article content html tag * refactor: migrate to v2 * fix: parse first jsonld only ---------
This commit is contained in:
parent
70f884e218
commit
e30cbac17f
|
|
@ -1443,7 +1443,7 @@ router.get('/xinquji/today/internal', lazyloadRouteHandler('./routes/xinquji/int
|
|||
router.get('/gbcc/trust', lazyloadRouteHandler('./routes/gbcc/trust'));
|
||||
|
||||
// CBC
|
||||
router.get('/cbc/topics/:topic?', lazyloadRouteHandler('./routes/cbc/topics'));
|
||||
// router.get('/cbc/topics/:topic?', lazyloadRouteHandler('./routes/cbc/topics'));
|
||||
|
||||
// discuz
|
||||
// router.get('/discuz/:ver([7|x])/:cid([0-9]{2})/:link(.*)', lazyloadRouteHandler('./routes/discuz/discuz'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/topics/:topic?': ['wb14123'],
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'cbc.ca': {
|
||||
_name: 'Canadian Broadcasting Corporation',
|
||||
'.': [
|
||||
{
|
||||
title: 'News',
|
||||
docs: 'https://docs.rsshub.app/routes/traditional-media#canadian-broadcasting-corporation',
|
||||
source: ['/news'],
|
||||
target: '/cbc/topics',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/topics/:topic?', require('./topics'));
|
||||
};
|
||||
|
|
@ -4,12 +4,9 @@ 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 url = `${baseUrl}/news${topic ? `/${topic.replace('-', '/')}` : ''}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url,
|
||||
});
|
||||
const response = await got(url);
|
||||
|
||||
const data = response.data;
|
||||
|
||||
|
|
@ -27,13 +24,13 @@ module.exports = async (ctx) => {
|
|||
$('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);
|
||||
links.map((link) =>
|
||||
ctx.cache.tryGet(link, async () => {
|
||||
const result = await got(link);
|
||||
|
||||
const $ = cheerio.load(result.data);
|
||||
|
||||
const head = JSON.parse($('script[type="application/ld+json"]').html());
|
||||
const head = JSON.parse($('script[type="application/ld+json"]').first().text());
|
||||
if (!head) {
|
||||
return [];
|
||||
}
|
||||
|
|
@ -44,28 +41,16 @@ module.exports = async (ctx) => {
|
|||
author = head.author.map((author) => author.name).join(' & ');
|
||||
}
|
||||
const pubDate = head.datePublished;
|
||||
const description = $('div.storyWrapper').html();
|
||||
const description = $('div[data-cy=storyWrapper]').html();
|
||||
|
||||
return [title, author, pubDate, description];
|
||||
});
|
||||
|
||||
if (!title) {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
pubDate,
|
||||
link,
|
||||
author,
|
||||
};
|
||||
})
|
||||
return { title, author, pubDate, description, link };
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: url,
|
||||
item: out.filter((x) => x),
|
||||
item: out.filter((x) => x.title),
|
||||
};
|
||||
};
|
||||
|
|
@ -163,11 +163,11 @@ Refer to [Boston.com's feed page](https://www.boston.com/rss-feeds) for tags. Fo
|
|||
|
||||
</Route>
|
||||
|
||||
## CBC {#cbc}
|
||||
## Canadian Broadcasting Corporation {#canadian-broadcasting-corporation}
|
||||
|
||||
通过提取文章全文,以提供比官方源更佳的阅读体验。
|
||||
### News {#canadian-broadcasting-corporation-news}
|
||||
|
||||
<Route author="wb14123" example="/cbc/topics" path="/cbc/topics/:topic?" paramsDesc={['CBC 频道。默认为 Top Stories。二级话题如 canada/toronto,需要用 `-` 替换掉 `/`。']}/>
|
||||
<Route author="wb14123" example="/cbc/topics" path="/cbc/topics/:topic?" paramsDesc={['Channel,`Top Stories` by default. For secondary channel like `canada/toronto`, use `-` to replace `/`']} radar="1"/>
|
||||
|
||||
## Chicago Tribune {#chicago-tribune}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue