Files
RSSHub/lib/routes/zzu/math.ts
T
Tony 5527d18de9 refactor: remove unnecessary trim/first/last (#22837)
* refactor: remove unnecessary trim/first/last

* refactor(types): allow null in DataItem.description

* refactor: remove unnecessary fallback

* refactor(types): allow null in Data.description

* refactor: remove unnecessary fallback

* refactor: remove .clone()

* refactor: refine json content text

* fIx: cognition

* fix: more fixes

* fix(route/jiemian): use api

* fix(route/jandan): housekeeping

add back maintainers from #8904

* fix(route/kcna/news): update source and target mappings

* fix(route/jandan): sanitize HTML content in titles

* refactor: remove unnecessary referer

* fix(route/jinse): regex
2026-07-27 22:23:57 +08:00

71 lines
2.1 KiB
TypeScript

import { load } from 'cheerio';
import type { Route } from '@/types';
import got from '@/utils/got';
export const route: Route = {
path: '/math/:type',
categories: ['university'],
example: '/zzu/math/xyxw',
parameters: { type: '分类名' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['www5.zzu.edu.cn/math/'],
},
],
name: '郑大数学与统计学院',
maintainers: ['amandus1990'],
handler,
description: `| 学院新闻 | 通知公告 | 党工团学 | 学术报告 |
| -------- | -------- | -------- | -------- |
| xyxw | tzgg | dgtx | xsbg |`,
};
async function handler(ctx) {
const type = ctx.req.param('type');
const typeDict = {
xyxw: ['学院新闻', 'https://www5.zzu.edu.cn/math/index/xyxw.htm'],
tzgg: ['通知公告', 'https://www5.zzu.edu.cn/math/index/tzgg.htm'],
dgtx: ['党工团学', 'https://www5.zzu.edu.cn/math/index/dgtx.htm'],
xsbg: ['学术报告', 'https://www5.zzu.edu.cn/math/index/xsbg.htm'],
};
// 获取页面内容
const response = await got(typeDict[type][1]);
const $ = load(response.data);
// 解析页面内容并提取文章信息
const list = $('.text-list ul li')
.toArray()
.slice(0, 16)
.map((element) => {
const $element = $(element);
const $link = $element.find('a');
const link = new URL($link.attr('href'), typeDict[type][1]).href;
const title = $link.attr('title') || $link.text().trim();
// 获取发布时间
const pubDateText = $element.find('span').text();
return {
title,
link,
pubDate: pubDateText || null,
};
});
return {
title: `郑大数学与统计学院-${typeDict[type][0]}`,
link: typeDict[type][1],
item: list,
};
}