From 9d27edbd98d70b772eba7392030a003f9352b74e Mon Sep 17 00:00:00 2001 From: LMark <40017222+ladeng07@users.noreply.github.com> Date: Wed, 10 Sep 2025 00:01:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=96=B0=E5=A2=9E=E5=8D=97?= =?UTF-8?q?=E5=BC=80=E5=A4=A7=E5=AD=A6=E4=BA=BA=E5=B7=A5=E6=99=BA=E8=83=BD?= =?UTF-8?q?=E5=AD=A6=E9=99=A2=E9=80=9A=E7=9F=A5=E8=B7=AF=E7=94=B1=20(#2000?= =?UTF-8?q?6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix nikkei/news * fix import * 新增南开大学人工智能学院官通知路由 * 删除pnpm-lock.yaml * 恢复 * 恢复旧的yaml * 修改selector * 修复名称错误 --------- Co-authored-by: 爱特未来来了 --- lib/routes/nankai/ai-notice.ts | 142 +++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 lib/routes/nankai/ai-notice.ts diff --git a/lib/routes/nankai/ai-notice.ts b/lib/routes/nankai/ai-notice.ts new file mode 100644 index 000000000..f04bf8a7f --- /dev/null +++ b/lib/routes/nankai/ai-notice.ts @@ -0,0 +1,142 @@ +import { Route } from '@/types'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import cache from '@/utils/cache'; +import timezone from '@/utils/timezone'; + +export const route: Route = { + path: '/ai/:type?', + categories: ['university'], + example: '/nankai/ai/zxdt', + parameters: { type: '栏目类型(若为空则默认为"最新动态")' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['ai.nankai.edu.cn', 'ai.nankai.edu.cn/xwzx/:type.htm'], + target: '/ai/:type?', + }, + ], + name: '人工智能学院', + maintainers: ['LMark'], + description: `| 最新动态 | 学院公告 | 学生之窗 | 科研信息 | 本科生教学 | 党团园地 | 研究生招生 | 研究生教学 | 就业信息 | 国际交流 | +| -------- | -------- | -------- | -------- | ---------- | -------- | ---------- | ---------- | -------- | -------- | +| zxdt | xygg | xszc | kyxx | bksjx | dtyd | yjszs | yjsjx | jyxx | gjjl |`, + url: 'ai.nankai.edu.cn', + handler: async (ctx) => { + // 从 URL 参数中获取通知分类 + const { type = 'zxdt' } = ctx.req.param(); + const baseUrl = 'https://ai.nankai.edu.cn'; + const { data: response } = await got(`${baseUrl}/xwzx/${type}.htm`); + const $ = load(response); + + // 获取分类名称映射 + const categoryMap: Record = { + zxdt: '最新动态', + xygg: '学院公告', + xszc: '学生之窗', + kyxx: '科研信息', + bksjx: '本科生教学', + dtyd: '党团园地', + yjszs: '研究生招生', + yjsjx: '研究生教学', + jyxx: '就业信息', + gjjl: '国际交流', + }; + + const categoryName = categoryMap[type] || '最新动态'; + + // 解析新闻列表 + const list = $('.gage-list-news table tr') + .slice(1) // 跳过表头 + .toArray() + .map((tr) => { + const $tr = $(tr); + const cells = $tr.find('td'); + + if (cells.length < 3) { + return null; + } + + const titleCell = cells.eq(0); + const sourceCell = cells.eq(1); + const dateCell = cells.eq(2); + + // 提取标题和链接 + const $titleLink = titleCell.find('a'); + const title = $titleLink.text().trim(); + let link = $titleLink.attr('href') || ''; + + // 处理相对链接 + link = link && !link.startsWith('http') ? `${baseUrl}/${link}` : link; + + // 提取日期 + const dateStr = dateCell.text().trim(); + const pubDate = dateStr.includes('/') ? timezone(parseDate(dateStr, 'YYYY/MM/DD'), +8) : timezone(parseDate(dateStr), +8); + + // 提取来源 + const source = sourceCell.text().trim(); + + return { + title, + link, + pubDate, + author: source || '人工智能学院', + description: '', // 初始化description属性 + }; + }) + .filter((item) => item && item.link && item.title); // 过滤掉空项目和没有链接的项目 + + // 获取每篇文章的详细内容 + const items = await Promise.all( + list.map((item) => + item + ? cache.tryGet(item.link, async () => { + try { + const { data: response } = await got(item.link); + const $ = load(response); + + const $description = $('.v_news_content'); + + // 处理相对链接,转换为绝对链接 + if ($description.length > 0) { + // 处理图片 + $description.find('img').each((i, el) => { + const $el = $(el); + let src = $el.attr('src'); + + if (src && !src.startsWith('http')) { + src = `${baseUrl}${src}`; + $el.attr('src', src); + } + }); + } + + item.description = $description.html() || item.title; + } catch { + // 如果获取详细内容失败,返回基本信息 + item.description = item.title + ' (获取详细内容失败)'; + } + return item; + }) + : null + ) + ); + + return { + // 源标题 + title: `南开大学人工智能学院-${categoryName}`, + // 源链接 + link: `${baseUrl}/xwzx/${type}.htm`, + // 源文章 + item: items, + }; + }, +};