Files
RSSHub/lib/routes/caixin/utils.ts
T
Tony 1acb805799 style: migrate eslint to oxlint (#21224)
* chore: add oxlint support

* style: apply autofix

* style: apply autofix for toSorted

* style: use alternative api for nsfw-flag jsPlugins

* fix: git diff

* fix: codeql

* test: console.log

* style: update lint workflow to use Checkstyle SARIF converter

* style: remove debug log from extractDateFromURL function

* chore: use oxlint-json-to-sarif

* test: console.log

* test: remove console.log

* test: update cookie data expectation in getCookies test

https://github.com/mccutchen/go-httpbin/pull/235 breaks this

* style: type-aware linting

* style: enable type-aware linting for oxlint
2026-02-28 21:23:11 +08:00

48 lines
1.2 KiB
TypeScript

import { load } from 'cheerio';
import got from '@/utils/got';
import { renderArticle } from './templates/article';
const parseArticle = async (item) => {
if (new URL(item.link).hostname.endsWith('.blog.caixin.com')) {
return parseBlogArticle(item);
} else {
const { data: response } = await got(item.link);
const $ = load(response);
item.description = renderArticle({
item,
$,
});
if (item.audio) {
item.itunes_item_image = item.audio_image_url;
item.enclosure_url = item.audio;
item.enclosure_type = 'audio/mpeg';
}
return item;
}
};
const parseBlogArticle = async (item) => {
const response = await got(item.link);
const $ = load(response.data);
const article = $('#the_content').removeAttr('style');
article.find('img').removeAttr('style');
article
.find('p')
// Non-breaking space U+00A0, ` ` in html
// element.children[0].data === $(element, article).text()
.filter((_, element) => element.children[0].data === String.fromCodePoint(160))
.remove();
item.description = article.html();
return item;
};
export { parseArticle, parseBlogArticle };