Files
RSSHub/lib/routes/cna/utils.ts
T
Chih-Hsuan Yen b5bcb8a567 feat(route/cna): cleanup extracted full texts (#21962)
Here is a page with description-box:
https://www.cna.com.tw/news/aipl/202605070117.aspx

Explanation for the term 憲法第130條 is injected in the middle of a
paragraph and makes that paragraph hard to read. This change fixes that.
2026-05-23 05:21:45 +00:00

36 lines
1.1 KiB
TypeScript

import { load } from 'cheerio';
import got from '@/utils/got';
export async function getFullText(item) {
if (item.link.startsWith('https://www.youtube.com/')) {
return item;
}
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = load(detailResponse.data);
content('div.SubscriptionInner').remove();
content('.gmailNews').remove();
// Those boxes are for explaining terms. They are injected inline and interrupt reading.
// If readers want to learn about terms, they can learn more online.
content('.dictionary-box').remove();
// Those are for "延伸閱讀" links, which are not part of the main article.
content('.moreArticle').remove();
const topImage = content('.fullPic').html();
item.description = (topImage === null ? '' : topImage) + content('.paragraph').eq(0).html();
item.category = [
...content("meta[property='article:tag']")
.toArray()
.map((e) => e.attribs.content),
content('.active > a').text(),
];
return item;
}