* feat(route): add ZZU (Zhengzhou University) routes Add routes for Zhengzhou University departments: - news: 新闻网 (要闻速递、教学科研、基层动态、媒体郑大) - tzhb: 党委统战部 (工作动态、通知公告) - dzb: 党政办 (新闻资讯、通知公告) - dwzzb: 党委组织部 (党建工作、干部工作、人才工作、乡村振兴工作) - xuan: 党委宣传部 (工作动态、通知公告) - rsc: 人事部 (人事要闻、通知公告、招聘公告) - jwc: 教务部 (新闻快递、通知公告) - student: 学生处 (新闻资讯、通知公告) - kjc: 科研院 (新闻资讯、通知公告) - ss: 社科院 (新闻资讯、通知公告) - zcycwb: 资产与财务部 (新闻资讯、通知公告) - gs: 研究生院 (新闻资讯、通知公告) - xbx: 校长办 (新闻资讯、通知公告) * refactor(routes): replace puppeteer with API in dwzzb and fix code style issues - refactor(dwzzb): use /mp/portal/article/list API endpoint instead of puppeteer - refactor(all zzu routes): rename type_dict to typeDict (camelCase) - refactor(dzb, tzhb): remove useless mapping operations - fix: update maintainers from 'misty' to 'amandus1990' * refactor(routes/zzu): optimize code style and fix date format - refactor(student): convert date format from 'yyyy年mm月dd日' to RFC 2822 - fix(tzhb): correct radar URL (hhttps -> https) - refactor: simplify typeDict formatting across all routes - refactor: adjust slice limits for better pagination (20 -> 10/15) - refactor(gs, jwc): simplify title extraction and date cleaning * fix(routes/zzu): fix date parsing and radar source URLs - fix(ss): handle different date formats for xwzx (MM-DD) and tzgg (yyyy-mm-dd) - fix(student): parse Chinese date format (yyyy年mm月dd日) using regex instead of Date constructor - refactor(all zzu routes): remove protocol from radar[].source URLs - radar rules can only match URL pathname, not protocol or query strings
80 lines
2.3 KiB
TypeScript
80 lines
2.3 KiB
TypeScript
import { load } from 'cheerio';
|
|
|
|
import type { Route } from '@/types';
|
|
import got from '@/utils/got';
|
|
|
|
export const route: Route = {
|
|
path: '/student/:type',
|
|
categories: ['university'],
|
|
example: '/zzu/student/xwzx',
|
|
parameters: { type: '分类名' },
|
|
features: {
|
|
requireConfig: false,
|
|
requirePuppeteer: false,
|
|
antiCrawler: false,
|
|
supportBT: false,
|
|
supportPodcast: false,
|
|
supportScihub: false,
|
|
},
|
|
radar: [
|
|
{
|
|
source: ['www5.zzu.edu.cn/student/'],
|
|
},
|
|
],
|
|
name: '郑大学生处',
|
|
maintainers: ['amandus1990'],
|
|
handler,
|
|
description: `| 新闻资讯 | 通知公告 |
|
|
| -------- | -------- |
|
|
| xwzx | tzgg |`,
|
|
};
|
|
|
|
async function handler(ctx) {
|
|
const type = ctx.req.param('type');
|
|
const typeDict = {
|
|
xwzx: ['新闻资讯', 'https://www5.zzu.edu.cn/student/xwzx.htm'],
|
|
tzgg: ['通知公告', 'https://www5.zzu.edu.cn/student/tzgg.htm'],
|
|
};
|
|
|
|
// 获取页面内容
|
|
const response = await got(typeDict[type][1]);
|
|
const $ = load(response.data);
|
|
|
|
// 解析页面内容并提取文章信息
|
|
const list = $('.part-list ul li')
|
|
.toArray()
|
|
.slice(0, 10)
|
|
.map((element) => {
|
|
const $element = $(element);
|
|
const $link = $element.find('a').first();
|
|
const link = new URL($link.attr('href'), typeDict[type][1]).href;
|
|
const title = $link.find('span').text().trim();
|
|
|
|
// 获取发布时间 (格式: yyyy年mm月dd日)
|
|
const pubDateText = $element.find('em').text().trim();
|
|
let pubDate = null;
|
|
|
|
if (pubDateText) {
|
|
const match = pubDateText.match(/(\d{4})年(\d{1,2})月(\d{1,2})日/);
|
|
if (match) {
|
|
const year = match[1];
|
|
const month = match[2].padStart(2, '0');
|
|
const day = match[3].padStart(2, '0');
|
|
pubDate = `${year}-${month}-${day}`;
|
|
}
|
|
}
|
|
|
|
return {
|
|
title,
|
|
link,
|
|
pubDate,
|
|
};
|
|
});
|
|
|
|
return {
|
|
title: `郑大学生处-${typeDict[type][0]}`,
|
|
link: typeDict[type][1],
|
|
item: list,
|
|
};
|
|
}
|