feat(routes/hrbust): add 'cs' 'gzc' 'lib' routes, unified code style (#18393)
This commit is contained in:
parent
20efa93a21
commit
f4225856b5
|
|
@ -0,0 +1,100 @@
|
|||
import { Route, ViewType } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
import { load } from 'cheerio';
|
||||
import { ofetch } from 'ofetch';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/cs/:category?',
|
||||
name: '计算机学院',
|
||||
url: 'cs.hrbust.edu.cn',
|
||||
maintainers: ['cscnk52'],
|
||||
handler,
|
||||
example: '/hrbust/cs',
|
||||
parameters: { category: '栏目标识,默认为 3709(学院要闻)' },
|
||||
description: `| 通知公告 | 学院要闻 | 常用下载 | 博士后流动站 | 学生指导 | 科研动态 | 科技成果 | 党建理论 | 党建学习 | 党建活动 | 党建风采 | 团学组织 | 学生党建 | 学生活动 | 心理健康 | 青春榜样 | 就业工作 | 校友风采 | 校庆专栏 | 专业介绍 | 本科生培养方案 | 硕士生培养方案 | 能力作风建设 | 博士生培养方案 | 省级实验教学示范中心 | 喜迎二十大系列活动 | 学习贯彻省十三次党代会精神 |
|
||||
|----------|----------|----------|--------------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------|----------------|----------------|--------------|----------------|----------------------|--------------------|----------------------------|
|
||||
| 3708 | 3709 | 3710 | 3725 | 3729 | 3732 | 3733 | 3740 | 3741 | 3742 | 3743 | 3744 | 3745 | 3746 | 3747 | 3748 | 3751 | 3752 | 3753 | 3755 | 3756 | 3759 | nlzfjs | pyfa | sjsyjxsfzx | srxxgcddesdjs | xxgcssscddhjs |`,
|
||||
categories: ['university'],
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
supportRadar: true,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['cs.hrbust.edu.cn/:category/list.htm'],
|
||||
target: '/cs/:category',
|
||||
},
|
||||
{
|
||||
source: ['cs.hrbust.edu.cn'],
|
||||
target: '/cs',
|
||||
},
|
||||
],
|
||||
view: ViewType.Notifications,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const rootUrl = 'https://cs.hrbust.edu.cn/';
|
||||
const { category = 3709 } = ctx.req.param();
|
||||
const columnUrl = `${rootUrl}${category}/list.htm`;
|
||||
const response = await ofetch(columnUrl);
|
||||
const $ = load(response);
|
||||
const bigTitle = $('li.col_title').text();
|
||||
|
||||
const list = $('div.col_news_con li.news')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
const element = $(item);
|
||||
const link = new URL(element.find('a').attr('href'), rootUrl).href;
|
||||
const pubDateText = element.find('span.news_meta').text().trim();
|
||||
const pubDate = pubDateText ? timezone(parseDate(pubDateText), +8) : null;
|
||||
return {
|
||||
title: element.find('a').text().trim(),
|
||||
pubDate,
|
||||
link,
|
||||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
if (!item.link.startsWith(rootUrl)) {
|
||||
item.description = '本文需跳转,请点击原文链接后阅读';
|
||||
return item;
|
||||
}
|
||||
|
||||
const response = await ofetch(item.link);
|
||||
const $ = load(response);
|
||||
const content = $('div.wp_articlecontent');
|
||||
|
||||
content.find('[style]').removeAttr('style');
|
||||
content.find('font').contents().unwrap();
|
||||
content.html(content.html()?.replaceAll(' ', ''));
|
||||
content.find('[align]').removeAttr('align');
|
||||
|
||||
const author = $('span.arti_publisher').text().replace('发布者:', '').trim();
|
||||
|
||||
return {
|
||||
title: item.title,
|
||||
link: item.link,
|
||||
pubDate: item.pubDate,
|
||||
description: content.html(),
|
||||
author,
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
title: `${bigTitle} - 哈尔滨理工大学计算机学院`,
|
||||
link: columnUrl,
|
||||
language: 'zh-CN',
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
import { Route, ViewType } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
import { load } from 'cheerio';
|
||||
import { ofetch } from 'ofetch';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/gzc/:category?',
|
||||
name: '国有资产管理处',
|
||||
url: 'gzc.hrbust.edu.cn',
|
||||
maintainers: ['cscnk52'],
|
||||
handler,
|
||||
example: '/hrbust/gzc',
|
||||
parameters: { category: '栏目标识,默认为 1305(热点新闻)' },
|
||||
description: `| 政策规章 | 资料下载 | 处务公开 | 招标信息 | 岗位职责 | 管理办法 | 物资处理 | 工作动态 | 热点新闻 |
|
||||
|----------|----------|----------|----------|----------|----------|----------|----------|----------|
|
||||
| 1287 | 1288 | 1289 | 1291 | 1300 | 1301 | 1302 | 1304 | 1305 |`,
|
||||
categories: ['university'],
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
supportRadar: true,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['gzc.hrbust.edu.cn/:category/list.htm'],
|
||||
target: '/gzc/:category',
|
||||
},
|
||||
{
|
||||
source: ['gzc.hrbust.edu.cn'],
|
||||
target: '/gzc',
|
||||
},
|
||||
],
|
||||
view: ViewType.Notifications,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const rootUrl = 'https://gzc.hrbust.edu.cn/';
|
||||
const { category = 1305 } = ctx.req.param();
|
||||
const columnUrl = `${rootUrl}${category}/list.htm`;
|
||||
const response = await ofetch(columnUrl);
|
||||
const $ = load(response);
|
||||
const bigTitle = $('li.col-title').text();
|
||||
|
||||
const list = $('ul.wp_article_list li.list_item')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
const element = $(item);
|
||||
const link = new URL(element.find('a').attr('href'), rootUrl).href;
|
||||
const pubDateText = element.find('span.Article_PublishDate').text().trim();
|
||||
const pubDate = pubDateText ? timezone(parseDate(pubDateText), +8) : null;
|
||||
return {
|
||||
title: element.find('a').text().trim(),
|
||||
pubDate,
|
||||
link,
|
||||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
if (!item.link.startsWith(rootUrl)) {
|
||||
item.description = '本文需跳转,请点击原文链接后阅读';
|
||||
return item;
|
||||
}
|
||||
|
||||
const response = await ofetch(item.link);
|
||||
const $ = load(response);
|
||||
const content = $('div.wp_articlecontent');
|
||||
|
||||
content.find('[style]').removeAttr('style');
|
||||
content.find('font').contents().unwrap();
|
||||
content.html(content.html()?.replaceAll(' ', ''));
|
||||
content.find('[align]').removeAttr('align');
|
||||
|
||||
return {
|
||||
title: item.title,
|
||||
link: item.link,
|
||||
pubDate: item.pubDate,
|
||||
description: content.html(),
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
title: `${bigTitle} - 哈尔滨理工大学国有资产管理处`,
|
||||
link: columnUrl,
|
||||
language: 'zh-CN',
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
|
|
@ -40,11 +40,10 @@ export const route: Route = {
|
|||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const JWZXBASE = 'http://jwzx.hrbust.edu.cn/homepage/';
|
||||
const rootUrl = 'http://jwzx.hrbust.edu.cn/homepage/';
|
||||
const { type = 354, page = 12 } = ctx.req.param();
|
||||
const url = JWZXBASE + 'infoArticleList.do?columnId=' + type + '&pagingNumberPer=' + page;
|
||||
|
||||
const response = await ofetch(url);
|
||||
const columnUrl = rootUrl + 'infoArticleList.do?columnId=' + type + '&pagingNumberPer=' + page;
|
||||
const response = await ofetch(columnUrl);
|
||||
const $ = load(response);
|
||||
|
||||
const bigTitle = $('.columnTitle .wow span').text().trim();
|
||||
|
|
@ -53,7 +52,7 @@ async function handler(ctx) {
|
|||
.toArray()
|
||||
.map((item) => {
|
||||
const element = $(item);
|
||||
const link = new URL(element.find('a').attr('href'), JWZXBASE).href;
|
||||
const link = new URL(element.find('a').attr('href'), rootUrl).href;
|
||||
const title = element.find('a').text().trim();
|
||||
const pubDateText = element.find('span').text().trim();
|
||||
const pubDate = timezone(parseDate(pubDateText), +8);
|
||||
|
|
@ -67,7 +66,7 @@ async function handler(ctx) {
|
|||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
if (!item.link.startsWith(JWZXBASE)) {
|
||||
if (!item.link.startsWith(rootUrl)) {
|
||||
item.description = '本文需跳转,请点击原文链接后阅读';
|
||||
return item;
|
||||
}
|
||||
|
|
@ -89,8 +88,9 @@ async function handler(ctx) {
|
|||
);
|
||||
|
||||
return {
|
||||
title: `哈尔滨理工大学教务处 - ${bigTitle}`,
|
||||
link: JWZXBASE,
|
||||
title: `${bigTitle} - 哈尔滨理工大学教务处`,
|
||||
link: columnUrl,
|
||||
language: 'zh-CN',
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,97 @@
|
|||
import { Route, ViewType } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
import { load } from 'cheerio';
|
||||
import { ofetch } from 'ofetch';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/lib/:category?',
|
||||
name: '图书馆',
|
||||
url: 'lib.hrbust.edu.cn',
|
||||
maintainers: ['cscnk52'],
|
||||
handler,
|
||||
example: '/hrbust/lib',
|
||||
parameters: { category: '栏目标识,默认为 3421(公告消息)' },
|
||||
description: `| 公告消息 | 资源动态 | 参考中心 | 常用工具 | 外借服务 | 报告厅及研讨间服务 | 外文引进数据库 | 外文电子图书 | 外文试用数据库 | 中文引进数据库 | 中文电子图书 | 中文试用数据库 |
|
||||
|----------|----------|----------|----------|----------|--------------------|----------------|--------------|----------------|----------------|--------------|----------------|
|
||||
| 3421 | 3422 | ckzx | cygj | wjfw | ytjfw | yw | yw_3392 | yw_3395 | zw | zw_3391 | zw_3394 |`,
|
||||
categories: ['university'],
|
||||
features: {
|
||||
requireConfig: false,
|
||||
requirePuppeteer: false,
|
||||
antiCrawler: false,
|
||||
supportBT: false,
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
supportRadar: true,
|
||||
},
|
||||
radar: [
|
||||
{
|
||||
source: ['lib.hrbust.edu.cn/:category/list.htm'],
|
||||
target: '/lib/:category',
|
||||
},
|
||||
{
|
||||
source: ['lib.hrbust.edu.cn'],
|
||||
target: '/lib',
|
||||
},
|
||||
],
|
||||
view: ViewType.Notifications,
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
const rootUrl = 'https://lib.hrbust.edu.cn/';
|
||||
const { category = 3421 } = ctx.req.param();
|
||||
const columnUrl = `${rootUrl}${category}/list.htm`;
|
||||
const response = await ofetch(columnUrl);
|
||||
const $ = load(response);
|
||||
const bigTitle = $('span.Column_Anchor').text();
|
||||
|
||||
const list = $('ul.tu_b3 li:not([class])')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
const element = $(item);
|
||||
const link = new URL(element.find('a').attr('href'), rootUrl).href;
|
||||
const pubDateText = element.find('span').text().trim();
|
||||
const pubDate = pubDateText ? timezone(parseDate(pubDateText), +8) : null;
|
||||
return {
|
||||
title: element.find('a').text().trim(),
|
||||
pubDate,
|
||||
link,
|
||||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
if (!item.link.startsWith(rootUrl)) {
|
||||
item.description = '本文需跳转,请点击原文链接后阅读';
|
||||
return item;
|
||||
}
|
||||
|
||||
const response = await ofetch(item.link);
|
||||
const $ = load(response);
|
||||
const content = $('div.wp_articlecontent');
|
||||
|
||||
content.find('[style]').removeAttr('style');
|
||||
content.find('font').contents().unwrap();
|
||||
content.html(content.html()?.replaceAll(' ', ''));
|
||||
content.find('[align]').removeAttr('align');
|
||||
|
||||
return {
|
||||
title: item.title,
|
||||
link: item.link,
|
||||
pubDate: item.pubDate,
|
||||
description: content.html(),
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
return {
|
||||
title: `${bigTitle} - 哈尔滨理工大学图书馆`,
|
||||
link: columnUrl,
|
||||
language: 'zh-CN',
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
import { Route, ViewType } 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';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
|
||||
export const route: Route = {
|
||||
path: '/news/:category?',
|
||||
|
|
@ -41,12 +41,10 @@ export const route: Route = {
|
|||
|
||||
async function handler(ctx) {
|
||||
const rootUrl = 'https://news.hrbust.edu.cn/';
|
||||
|
||||
const { category = 'lgyw' } = ctx.req.param();
|
||||
|
||||
const response = await got(`${rootUrl}${category}.htm`);
|
||||
|
||||
const $ = load(response.data);
|
||||
const columnUrl = `${rootUrl}${category}.htm`;
|
||||
const response = await ofetch(columnUrl);
|
||||
const $ = load(response);
|
||||
|
||||
const bigTitle = $('title').text().split('-')[0].trim();
|
||||
|
||||
|
|
@ -72,8 +70,8 @@ async function handler(ctx) {
|
|||
return item;
|
||||
}
|
||||
|
||||
const detailResponse = await got(item.link);
|
||||
const content = load(detailResponse.data);
|
||||
const detailResponse = await ofetch(item.link);
|
||||
const content = load(detailResponse);
|
||||
|
||||
const dateText = content('p.xinxi span:contains("日期时间:")').text().replace('日期时间:', '').trim();
|
||||
const pubTime = dateText ? timezone(parseDate(dateText), +8) : null;
|
||||
|
|
@ -98,8 +96,9 @@ async function handler(ctx) {
|
|||
);
|
||||
|
||||
return {
|
||||
title: `哈尔滨理工大学新闻网 - ${bigTitle}`,
|
||||
link: `${rootUrl}${category}.htm`,
|
||||
title: `${bigTitle} - 哈尔滨理工大学新闻网`,
|
||||
link: columnUrl,
|
||||
language: 'zh-CN',
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,13 +41,9 @@ export const route: Route = {
|
|||
|
||||
async function handler(ctx) {
|
||||
const rootUrl = 'https://nic.hrbust.edu.cn/';
|
||||
|
||||
const { category = 3988 } = ctx.req.param();
|
||||
|
||||
const url = `${rootUrl}${category}/list.htm`;
|
||||
|
||||
const response = await ofetch(url);
|
||||
|
||||
const columnUrl = `${rootUrl}${category}/list.htm`;
|
||||
const response = await ofetch(columnUrl);
|
||||
const $ = load(response);
|
||||
|
||||
const bigTitle = $('li.col_title').text();
|
||||
|
|
@ -93,8 +89,9 @@ async function handler(ctx) {
|
|||
);
|
||||
|
||||
return {
|
||||
title: `哈尔滨理工大学网络信息中心 - ${bigTitle}`,
|
||||
link: rootUrl,
|
||||
title: `${bigTitle} - 哈尔滨理工大学网络信息中心`,
|
||||
link: columnUrl,
|
||||
language: 'zh-CN',
|
||||
item: items,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue