* fix(route): fix wrong title of /ecnu/bksy Co-authored-by: FrozenStarrrr <frozenstars@qq.com> * feat(route): add ECNU Software Engineering Insitute notices route * fix(route): modify wrong radar target * add School of Computer Science and Technology ECNU notices route * add School of data science and engineering notices route * add School of Comm. & Elec. Engineering notices route * add School of Geospace A.I. Engineering ECNU notices route * add ECNU faculty of Edu. notices route * add ECNU faculty of Earth Sci. notices route * add ECNU Meng Xiancheng notices route * add ECNU Guanghua notices route * fix(route): add empty line at the end of files. * add department of history ECNU notices route * add department of Philo. ECNU notices route * fix(route): add maintainer of /ecnu/bksy * fix(route): delete unnecessary try-catch statment, modified incorrect url, fix image url. * fix(route): fix unnecessary try-catch, description, condition and wrond url * fix(route): fix image display * fix(route): fix problems in bksy.ts * feat(route): add ecnu/pharm * feat(route): add art insititute of ECNU * feat(route): add route of school of Stat. ECNU * feat(route): add route of school of Phy. & Elec., ECNU * feat(route): add route of school of Chem. & Mol., ECNU * feat(route): add route of school of Eco. & Envir., ECNU * feat(route): add route of school of Comm., ECNU * feat(route): add route of school of International Chinese Studies, ECNU * feat(route): add route of school of Psy. & cognitive Sci., ECNU * feat(route): add route of college of Phy. Edu. & health , ECNU * feat(route): add route of college of public management, ECNU * feat(route): add route of college of Marxismus, ECNU * fix(routes): fix incorrect time display and remove unnecessary codes * fix(foute): format the code --------- Co-authored-by: FrozenStarrrr <frozenstars@qq.com>
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import { load } from 'cheerio';
|
|
|
|
import type { Route } from '@/types';
|
|
import cache from '@/utils/cache';
|
|
import got from '@/utils/got';
|
|
import { parseDate } from '@/utils/parse-date';
|
|
import timezone from '@/utils/timezone';
|
|
|
|
export const route: Route = {
|
|
path: '/phy',
|
|
categories: ['university'],
|
|
example: '/ecnu/phy',
|
|
radar: [
|
|
{
|
|
source: ['phy.ecnu.edu.cn'],
|
|
target: '/phy',
|
|
},
|
|
],
|
|
name: '物理与电子科学学院通知公告',
|
|
maintainers: ['FrozenStarrrr', 'ChiyoYuki', 'ECNU-minus'],
|
|
handler: async () => {
|
|
const baseUrl = 'https://phy.ecnu.edu.cn/';
|
|
|
|
const response = await got(`${baseUrl}1605/list.htm`);
|
|
const $ = load(response.data);
|
|
const links = $('ul.data-list > li')
|
|
.toArray()
|
|
.map((el) => ({
|
|
pubDate: timezone(parseDate($(el).find('span').text()), +8),
|
|
link: new URL($(el).find('a').attr('href'), baseUrl).toString(),
|
|
title: $(el).find('a').attr('title'),
|
|
}));
|
|
const items = await Promise.all(
|
|
links.map((item) =>
|
|
cache.tryGet(item.link, async () => {
|
|
const { data } = await got(item.link);
|
|
const $ = load(data);
|
|
const $read = $('div.wp_articlecontent');
|
|
$read.find('img[src], a[href]').each((i, el) => {
|
|
const $el = $(el);
|
|
const attr = el.tagName === 'img' ? 'src' : 'href';
|
|
const val = $el.attr(attr);
|
|
if (val) {
|
|
$el.attr(attr, new URL(val, baseUrl).toString());
|
|
}
|
|
});
|
|
item.description = $read.html()?.trim();
|
|
return item;
|
|
})
|
|
)
|
|
);
|
|
|
|
return {
|
|
title: '物理与电子科学学院通知公告',
|
|
link: 'https://phy.ecnu.edu.cn/1605/list.htm',
|
|
item: items,
|
|
};
|
|
},
|
|
};
|