Files
RSSHub/lib/routes/csust/utils.ts
T
powerfullz d454ef8f47 fix(route/csust): various fixes and improvements (#22704)
* fix(route/csust): self-contained routes, full title extraction, absolute URLs

- Remove factory pattern from utils.ts, keep only getNoticeContent helper
- Each route (tggs/xkxs) now self-contained with inline list parsing
- Extract full title from article page <title> tag to avoid truncation
- Convert relative URLs to absolute in article content

* fix(route/csust): remove redundant logics
2026-07-23 22:17:31 +08:00

27 lines
871 B
TypeScript

import { load } from 'cheerio';
import type { DataItem } from '@/types';
import got from '@/utils/got';
type NoticeItem = DataItem & { link: string };
export async function getNoticeContent(item: NoticeItem): Promise<NoticeItem> {
const response = await got(item.link);
const $ = load(response.body);
const pageTitle = $('title').text();
const $content = $('.v_news_content');
$content.find('script, style, .vsbcontent_end').remove();
$content.find('img[src], a[href]').each((_, element) => {
const $element = $(element);
const attribute = element.tagName === 'img' ? 'src' : 'href';
$element.attr(attribute, new URL($element.attr(attribute)!, item.link).href);
});
return {
...item,
title: pageTitle.slice(0, pageTitle.lastIndexOf('-')).trim(),
description: $content.html()!,
};
}