Files
Tony 5527d18de9 refactor: remove unnecessary trim/first/last (#22837)
* refactor: remove unnecessary trim/first/last

* refactor(types): allow null in DataItem.description

* refactor: remove unnecessary fallback

* refactor(types): allow null in Data.description

* refactor: remove unnecessary fallback

* refactor: remove .clone()

* refactor: refine json content text

* fIx: cognition

* fix: more fixes

* fix(route/jiemian): use api

* fix(route/jandan): housekeeping

add back maintainers from #8904

* fix(route/kcna/news): update source and target mappings

* fix(route/jandan): sanitize HTML content in titles

* refactor: remove unnecessary referer

* fix(route/jinse): regex
2026-07-27 22:23:57 +08:00

31 lines
859 B
TypeScript

import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import type { WPPost } from './types';
const processImages = ($) => {
$('a').each((_, elem) => {
const $elem = $(elem);
const largePhotoUrl = $elem.attr('href')?.replace('i0.wp.com', '').replace('pic.4khd.com', 'yt4.googleusercontent.com').replace('AsHYQ', 'AsYHQ').replace('l/AAA', 'I/AAA');
if (largePhotoUrl) {
$elem.attr('href', largePhotoUrl);
$elem.find('img').attr('src', largePhotoUrl);
}
});
};
function loadArticle(item: WPPost) {
const article = load(item.content.rendered);
processImages(article);
return {
title: item.title.rendered,
description: article.html(),
pubDate: parseDate(item.date_gmt),
link: item.link,
};
}
export default loadArticle;