mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
CBC feed has "Social Sharing" in its feed. This PR removes it since it's not needed in RSS feed.
59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
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 ? `/${topic.replace('-', '/')}` : ''}`;
|
|
|
|
const response = await got(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((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"]').first().text());
|
|
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 descriptionDom = $('div[data-cy=storyWrapper]');
|
|
descriptionDom.find('div[class=share]').remove();
|
|
const description = descriptionDom.html();
|
|
|
|
return { title, author, pubDate, description, link };
|
|
})
|
|
)
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title: $('title').text(),
|
|
link: url,
|
|
item: out.filter((x) => x.title),
|
|
};
|
|
};
|