feat(route): A new routing (tzggcdunews.ts) for https://news.cdu.edu.cn/tzgg.htm has been created (#18713)

* 为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

---------
This commit is contained in:
uuwor 2025-03-29 01:46:50 +08:00 committed by GitHub
parent 9d9da167bc
commit 994abe131b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 80 additions and 0 deletions

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: '/tzggcdunews',
categories: ['university'],
example: '/cdu/tzggcdunews',
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}/tzgg.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,
};
}