feat(route): add 湖南农业大学教务处等通知 (#12913)

* feat(route): add 湖南农业大学教务处等通知

* feat(route): add hunau湖南农业大学教务处等通知

* fix: Incomplete multi-character sanitization

* fix: sort entries

* fix: name using lowerCamelCase

* fix: case bugs
This commit is contained in:
甜檸seril
2023-07-31 00:12:14 +08:00
committed by GitHub
parent 8a6f750f8b
commit 93beaca55a
12 changed files with 286 additions and 0 deletions
+43
View File
@@ -1516,6 +1516,49 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS
</Route>
## 湖南农业大学
### 教务处
<Route author="lcandy2" example="/hunau/jwc" path="/hunau/jwc/:category?/:page?" :paramsDesc="['页面分类,默认为 `tzgg`', '页码,默认为 `1`']">
| 分类 | 通知公告 | 教务动态 | 其他教务通知... |
| ---- | -------- | -------- | --------------- |
| 参数 | tzgg | jwds | 对应 URL |
</Route>
### 国际交流与合作处、国际教育学院、港澳台事务办公室
<Route author="lcandy2" example="/hunau/ied" path="/hunau/ied/:type?/:category?/:page?" :paramsDesc="['页面归属,默认为 `xwzx`','页面分类,默认为 `ggtz`', '页码,默认为 `1`']">
| 分类 | 公告通知 | 新闻快讯 | 其他分类... |
| -------- | -------- | -------- | ----------- |
| type | xwzx | xwzx | 对应 URL |
| category | tzgg | xwkx | 对应 URL |
</Route>
### 公共管理与法学学院
<Route author="lcandy2" example="/hunau/gfxy" path="/hunau/gfxy/:category?/:page?" :paramsDesc="['页面分类,默认为 `tzgg`', '页码,默认为 `1`']">
| 分类 | 通知公告 | 学院新闻 | 其他分类通知... |
| ---- | -------- | -------- | --------------- |
| 参数 | tzgg | xyxw | 对应 URL |
</Route>
### 信息与智能科学学院
<Route author="lcandy2" example="/hunau/xky" path="/hunau/xky/:category?/:page?" :paramsDesc="['页面分类,默认为 `tzgg_8472`', '页码,默认为 `1`']">
| 分类 | 通知公告 | 学院新闻 | 其他分类通知... |
| ---- | --------- | -------- | --------------- |
| 参数 | tzgg_8472 | xyxw | 对应 URL |
</Route>
## 华北电力大学
### 北京校区研究生院
+11
View File
@@ -0,0 +1,11 @@
const getContent = require('../utils/common');
module.exports = async (ctx) => {
await getContent(ctx, {
baseHost: 'https://gfxy.hunau.edu.cn',
baseCategory: 'tzgg', // 默认:通知公告
baseTitle: '公共管理与法学学院',
baseDescription: '湖南农业大学公共管理与法学学院',
baseDeparment: 'gfxy',
});
};
+12
View File
@@ -0,0 +1,12 @@
const getContent = require('./utils/common');
module.exports = async (ctx) => {
await getContent(ctx, {
baseHost: 'https://ied.hunau.edu.cn',
baseCategory: 'ggtz', // 默认:公告通知
baseType: 'xwzx', // 默认:新闻中心
baseTitle: '国际交流与合作处',
baseDescription: '湖南农业大学国际交流与合作处、国际教育学院、港澳台事务办公室',
baseDeparment: 'ied',
});
};
+10
View File
@@ -0,0 +1,10 @@
const getContent = require('./utils/common');
module.exports = async (ctx) => {
await getContent(ctx, {
baseHost: 'https://jwc.hunau.edu.cn',
baseCategory: 'tzgg', // 默认:通知公告
baseTitle: '湖南农业大学教务处',
baseDeparment: 'jwc',
});
};
+6
View File
@@ -0,0 +1,6 @@
module.exports = {
'/gfxy/:type?/:page?': ['lcandy2'],
'/ied/:type?/:category?/:page?': ['lcandy2'],
'/jwc/:type?/:page?': ['lcandy2'],
'/xky/:type?/:page?': ['lcandy2'],
};
+37
View File
@@ -0,0 +1,37 @@
module.exports = {
'hunau.edu.cn': {
_name: '湖南农业大学',
gfxy: [
{
title: '公共管理与法学学院',
docs: 'https://docs.rsshub.app/university.html#hu-nan-nong-ye-da-xue',
source: ['/', 'tzgg', '/:category'],
target: '/:category',
},
],
ied: [
{
title: '国际交流与合作处',
docs: 'https://docs.rsshub.app/university.html#hu-nan-nong-ye-da-xue',
source: ['/', '/xwzx/ggtz', '/:type/:category'],
target: '/:type/:category',
},
],
jwc: [
{
title: '教务处',
docs: 'https://docs.rsshub.app/university.html#hu-nan-nong-ye-da-xue',
source: ['/', 'tzgg', '/:category'],
target: '/:category',
},
],
xky: [
{
title: '信息与智能科学技术学院',
docs: 'https://docs.rsshub.app/university.html#hu-nan-nong-ye-da-xue',
source: ['/', 'tzgg_8472', '/:category'],
target: '/:category',
},
],
},
};
+6
View File
@@ -0,0 +1,6 @@
module.exports = (router) => {
router.get('/gfxy/:category?/:page?', require('./gfxy'));
router.get('/ied/:type?/:category?/:page?', require('./ied'));
router.get('/jwc/:category?/:page?', require('./jwc'));
router.get('/xky/:category?/:page?', require('./xky'));
};
+31
View File
@@ -0,0 +1,31 @@
const categoryTitle = (type) => {
let title;
type = type.slice(0, 4).toLowerCase();
switch (type) {
case 'tzgg':
title = '通知公告';
break;
case 'ggtz':
title = '公告通知';
break;
case 'jwdt':
title = '教务动态';
break;
case 'xyxw':
title = '学院新闻';
break;
case 'jzxx':
title = '讲座信息';
break;
case 'xzzq':
title = '下载专区';
break;
default:
title = '';
}
return title;
};
module.exports = categoryTitle;
+61
View File
@@ -0,0 +1,61 @@
// common.js
const cheerio = require('cheerio');
const got = require('@/utils/got');
const categoryTitle = require('./categoryTitle');
const newsContent = require('./newsContent');
const indexPage = require('./indexPage');
async function getContent(ctx, { baseHost, baseCategory, baseType, baseTitle, baseDescription = '', baseDeparment = '', baseClass = 'div.article_list ul li:has(a)' }) {
const { category = baseCategory, type = baseType, page = '1' } = ctx.params;
const title = `${baseTitle} - ${categoryTitle(category)}`;
const description = baseDescription ? `${baseDescription} - ${categoryTitle(category)}` : title;
const typeURL = type ? `/${type}` : '';
const baseURl = `${baseHost}${typeURL}/${category}`;
const url = `${baseURl}/${indexPage(page)}`;
const { data: response } = await got(url);
const $ = cheerio.load(response);
const list = $(baseClass)
.toArray()
.map((item) => {
item = $(item);
const a = item.find('a');
const href = a.attr('href');
const title = a.text();
const link = href.startsWith('./') && !href.endsWith('.pdf') ? `${baseURl}${href.replace('./', '/')}` : href;
return {
title,
link,
};
});
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const content = await newsContent(item.link, baseDeparment);
item.pubDate = content.pubDate;
item.description = content.description;
return item;
})
)
);
ctx.state.data = {
// 源标题
title,
description,
// 源链接
link: url,
// 源文章
item: items,
};
}
module.exports = getContent;
+10
View File
@@ -0,0 +1,10 @@
const indexPage = (page) => {
const fileName = 'index';
const fileType = 'html';
const filePage = page === '1' ? '' : `_${parseInt(page) - 1}`;
return `${fileName}${filePage}.${fileType}`;
};
module.exports = indexPage;
+47
View File
@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const cheerio = require('cheerio');
async function newsContent(link, department = '') {
try {
// 异步请求文章
const { data: response } = await got(link, {
https: {
rejectUnauthorized: false,
},
});
// 加载文章内容
const $ = cheerio.load(response);
let reg = /\d{4}\/\d{2}\/\d{2}/;
let element = '.newscontent';
// 处理特定部门
if (department === 'xky') {
reg = /\d{4}-\d{2}-\d{2}/;
element = '.content .edit';
}
// 解析日期
const extractDate = ($('.info').first().html()?.match(reg) || [])[0];
const pubDate = timezone(parseDate(extractDate, 'YYYY-MM-DD', 'zh-cn'), +8);
// 解析文章
const newsContent = $(element).first();
newsContent.find('table').remove();
let description = newsContent.text().replace(/\s+/g, '');
// 处理特定部门
if (department === 'gfxy') {
description = description.replace('点击下载文件:', '');
}
// 返回解析的结果
return { description, pubDate };
} catch (error) {
// Handle the error (e.g., log it and return some default values)
// console.error(`There was an error fetching the link ${link}: ${error.message}`);
return { description: '', pubDate: null };
}
}
module.exports = newsContent;
+12
View File
@@ -0,0 +1,12 @@
const getContent = require('../utils/common');
module.exports = async (ctx) => {
await getContent(ctx, {
baseHost: 'https://xky.hunau.edu.cn',
baseCategory: 'tzgg_8472', // 默认:通知公告
baseTitle: '信息与智能科学技术学院',
baseDescription: '湖南农业大学信息与智能科学技术学院',
baseDeparment: 'xky',
baseClass: 'div.right_list ul li:has(a)',
});
};