feat(route): A new routing (cdrw.ts) has been created (#18786)

* 为jwgg.ts添加了部分注释;新建了路由tzggcdunews.ts

* Update jwgg.ts

Indentation has been added after the comments '//' or '/*'

* Update tzggcdunews.ts

Indentation has been added after the comments '//' or '/*'

* Update jwgg.ts

Adjusted Code format

* Update jwgg.ts

完整的 URL:在 url 字段中添加了协议部分(https://)。
选择器修正:直接在 title 中查找 <a> 标签而不是 tr.odd a,这减少了选择器的复杂度。
日期匹配检查:加入了对 dateMatch 的检查,以防止运行时错误。
使用模板字符串:在构建 link 时使用模板字符串,使代码更易读。
过滤无发布日期的项目:在返回结果时,过滤掉那些没有发布日期的项,以确保输出的数据质量。

* 重写tzggcdunews.ts;还原jwgg.ts

* Update lib/routes/cdu/tzggcdunews.ts

* Create news.ts

成大新闻

* Update news.ts

主要修复点
列表项选择器修正:

原代码使用$('a[title]')选择器不够精确

改为使用$('ul.ul-mzw-litpic-a2 li a.con')更精确地定位新闻条目

日期解析改进:

保持原有的两种日期格式处理逻辑

确保日期解析正确并转换为UTC+8时区

链接处理:

正确处理相对路径链接,使用new URL(link, rootUrl).href构建完整URL

标题提取:

从.tit元素中提取标题,而不是依赖title属性

详情页内容提取:

使用.v_news_content选择器获取正文内容

移除页脚等无关元素

RSS标题生成:

从页面标题和分类标题组合生成更有意义的RSS标题

错误处理:

添加了适当的错误处理逻辑,确保在元素不存在时不会报错

* Update news.ts

路由索引

* Create cdrw.ts

增添成大人物订阅

* Delete lib/routes/cdu/news.ts

DELETE NEWS.TS
This commit is contained in:
uuwor
2025-04-08 01:13:46 +08:00
committed by GitHub
parent 75c74aff94
commit 6dd5106441
+80
View File
@@ -0,0 +1,80 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
export const route: Route = {
path: '/cdrw',
categories: ['university'],
example: '/cdu/cdrw',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['news.cdu.edu.cn/'],
},
],
name: '成大人物',
maintainers: ['uuwor'],
handler,
url: 'news.cdu.edu.cn/',
};
async function handler() {
const baseUrl = 'https://news.cdu.edu.cn';
const url = `${baseUrl}/cdrw.htm`;
const response = await got.get(url);
const $ = load(response.data);
const list = $('.row-f1 ul.ul-mzw-news-a2 li a.con')
.slice(0, 10)
.toArray()
.map((item) => {
const element = $(item);
// 优先使用title属性内容,避免内容被截断
const title = element.attr('title') || element.find('.tit').text().trim();
const link = element.attr('href');
const dateText = element.find('.date').text().trim();
const pubDate = timezone(parseDate(dateText), 8);
return {
title,
// 处理相对路径链接
link: link.startsWith('http') ? link : new URL(link, baseUrl).href,
pubDate,
author: '成都大学新闻网',
};
});
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const response = await got.get(item.link);
const $ = load(response.data);
// 清理无关内容并提取正文
const content = $('.v_news_content');
// 移除版权声明等无关元素
content.find('*[style*="text-align: right"]').remove();
item.description = content.html();
return item;
})
)
);
return {
title: '人物',
link: url,
item: items,
};
}