feat(route): 添加南京晓庄学院 (#11125)

* add njxzc support

* add njxzc docs

* change title

* change njxzc wrong words

* remove lib and jwc

* change njxzc md postion

* change code writing to standard

* remove item.author and add item.title in cache

* fix operator wrong
This commit is contained in:
Jaya 2022-10-21 01:43:56 +08:00 committed by GitHub
parent 8ac5ca74c9
commit 9afdffcc69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 88 additions and 0 deletions

View File

@ -2161,6 +2161,12 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS
</Route>
## 南京晓庄学院
### 官网通知公告
<Route author="real-jiakai" example="/njxzc/tzgg" path="/njxzc/tzgg" />
## 南开大学
### 南开大学教务处

62
lib/v2/njxzc/home.js Normal file
View File

@ -0,0 +1,62 @@
// 导入got库该库用来请求网页数据
const got = require('@/utils/got');
// 导入cheerio库该库用来解析网页数据
const cheerio = require('cheerio');
// 导入parseDate函数该函数用于日期处理
const { parseDate } = require('@/utils/parse-date');
// 导入timezone库该库用于时区处理
const timezone = require('@/utils/timezone');
// 通知通告的url链接
const url = 'https://www.njxzc.edu.cn/89/list.htm';
// 南京晓庄学院的首页网址
const host = 'https://www.njxzc.edu.cn';
module.exports = async (ctx) => {
// 发起Http请求获取网页数据
const response = await got(url);
// 解析网页数据
const $ = cheerio.load(response.data);
// 通知公告的items的标题、url链接、发布日期
const list = $('.news_list .news')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('a').attr('title'),
link: host + item.find('a').attr('href'),
pubDate: timezone(parseDate(item.find('.news_meta').text(), 'YYYY-MM-DD'), +8),
};
});
const out = await Promise.all(
list.map((item) =>
// 使用缓存
ctx.cache.tryGet(item.link, async () => {
const response = await got(item.link);
const $ = cheerio.load(response.data);
item.title = $('.arti_title').text();
item.description = $('.wp_articlecontent')
.html()
.replace(/src="\//g, `src="${new URL('.', host).href}`)
.replace(/href="\//g, `href="${new URL('.', host).href}`)
.trim();
item.pubDate = timezone(parseDate($('.arti_update').text().replace('发布时间:', '')), +8);
return item;
})
)
);
// 生成RSS源
ctx.state.data = {
// 项目标题
title: '南京晓庄学院 -- 通知公告',
// 项目链接
link: url,
// items的内容
item: out,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/tzgg': ['real-jiakai'],
};

13
lib/v2/njxzc/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'njxzc.edu.cn': {
_name: '南京晓庄学院',
www: [
{
title: '通知公告',
docs: 'https://docs.rsshub.app/university.html#nan-jing-xiao-zhuang-xue-yuan-tong-zhi-gong-gao',
source: ['/89/list.htm', '/'],
target: '/njxzc/tzgg',
},
],
},
};

4
lib/v2/njxzc/router.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = (router) => {
// 南京晓庄学院官网通知公告
router.get('/tzgg', require('./home'));
};