feat(route): add jwc notice (#15357)
* add jwc * fix Move function definitions to the highest possible scope. Warning * Fix code non-standard format * Fix code non-standard format
This commit is contained in:
parent
df51c93677
commit
fb0b142b5a
|
|
@ -0,0 +1,65 @@
|
|||
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';
|
||||
|
||||
const type = (filename) => filename.split('.').pop();
|
||||
|
||||
export const route: Route = {
|
||||
path: '/jwc',
|
||||
categories: ['university'],
|
||||
example: '/ecnu/jwc',
|
||||
radar: [{
|
||||
source: ['www.jwc.ecnu.edu.cn', 'www.ecnu.edu.cn'],
|
||||
target: '/tzgg',
|
||||
}],
|
||||
name: '教务处通知',
|
||||
maintainers: ['markbang'],
|
||||
handler: async () => {
|
||||
const baseUrl = 'http://www.jwc.ecnu.edu.cn/';
|
||||
|
||||
const response = await got(`${baseUrl}tzggwwxsgg/list.htm`);
|
||||
const $ = load(response.data);
|
||||
const links = $('.col_news_con ul.news_list > li')
|
||||
.map((_, el) => ({
|
||||
pubDate: timezone(parseDate($(el).find('.news_date').text()), 8),
|
||||
link: new URL($(el).find('a').attr('href'), baseUrl).toString(),
|
||||
title: $(el).find('a').text(),
|
||||
}))
|
||||
.get();
|
||||
const items = await Promise.all(
|
||||
links.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
if (type(item.link) === 'htm') {
|
||||
try {
|
||||
const { data } = await got(item.link, {
|
||||
https: {
|
||||
rejectUnauthorized: false,
|
||||
},
|
||||
});
|
||||
const $ = load(data);
|
||||
item.description = $('div.article')?.html()?.replaceAll('src="/', `src="${baseUrl}/`)?.replaceAll('href="/', `href="${baseUrl}/`)?.trim();
|
||||
return item;
|
||||
} catch {
|
||||
// intranet
|
||||
item.description = '请进行统一身份认证之后再访问';
|
||||
return item;
|
||||
}
|
||||
} else {
|
||||
// file to download
|
||||
item.description = '点击认证后访问内容';
|
||||
return item;
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
title: '教务处通知',
|
||||
link: 'http://www.jwc.ecnu.edu.cn/tzggwwxsgg/list.htm',
|
||||
item: items,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
@ -2,5 +2,5 @@ import type { Namespace } from '@/types';
|
|||
|
||||
export const namespace: Namespace = {
|
||||
name: 'East China Normal University 华东师范大学',
|
||||
url: 'acm.ecnu.edu.cn',
|
||||
url: 'ecnu.edu.cn',
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue