Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 添加广西民族大学图书馆最新消息RSS的支持 #13364

Merged
merged 3 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions lib/v2/gxmzu/lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 导入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://library.gxmzu.edu.cn/news/news_list.jsp?urltype=tree.TreeTempUrl&wbtreeid=1010';
// 广西民大图书馆网址
const host = 'https://library.gxmzu.edu.cn';

module.exports = async (ctx) => {
// 发起Http请求,获取网页数据
const response = await got(url);

// 解析网页数据
const $ = cheerio.load(response.data);

// 通知公告的items的标题、url链接、发布日期
const list = $('#newslist ul li')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('a').text(),
link: new URL(item.find('a').attr('href'), host).href,
pubDate: timezone(parseDate(item.find('span').text(), 'YYYY-MM-DD'), +8),
};
});

const out = await Promise.all(
list.map((item) =>
// 使用缓存
ctx.cache.tryGet(item.link, async () => {
// 排除非本站点的外链
if (item.link && !item.link.startsWith('https://library.gxmzu.edu.cn')) {
Fixed Show fixed Hide fixed
real-jiakai marked this conversation as resolved.
Show resolved Hide resolved
item.description = '该通知无法直接预览,请点击原文链接↑查看';
return item;
}

// 爬取全文
const response = await got(item.link);

// 检查重定向
if (response.redirectUrls && response.redirectUrls.length > 0) {
item.link = response.redirectUrls[0];
item.description = '该通知无法直接预览,请点击原文链接↑查看';
} else {
const $ = cheerio.load(response.data);
item.title = $('h2').text();
item.description = $('.v_news_content').html();
}
return item;
})
)
);

// 生成RSS源
ctx.state.data = {
// 项目标题
title: '广西民族大学图书馆 -- 最新消息',
// 项目链接
link: url,
// items的内容
item: out,
};
};
1 change: 1 addition & 0 deletions lib/v2/gxmzu/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
'/aitzgg': ['real-jiakai'],
'/libzxxx': ['real-jiakai'],
'/yjszsgg': ['real-jiakai'],
};
8 changes: 8 additions & 0 deletions lib/v2/gxmzu/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ module.exports = {
target: '/gxmzu/aitzgg',
},
],
library: [
{
title: '图书馆最新消息',
docs: 'https://docs.rsshub.app/routes/unversity#guang-xi-min-zu-da-xue-tu-shu-guan-zui-xin-xiao-xi',
source: ['/news/news_list.jsp', '/'],
target: '/gxmzu/libzxxx',
},
],
yjs: [
{
title: '研究生院招生公告',
Expand Down
1 change: 1 addition & 0 deletions lib/v2/gxmzu/router.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = (router) => {
router.get('/aitzgg', require('./ai'));
router.get('/libzxxx', require('./lib'));
router.get('/yjszsgg', require('./yjs'));
};
4 changes: 4 additions & 0 deletions website/docs/routes/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,10 @@ Note:[Source website](https://ece.umass.edu/seminar) may be empty when there's

<Route author="real-jiakai" example="/gxmzu/aitzgg" path="/gxmzu/aitzgg" radar="1" />

### 图书馆最新消息 {#guang-xi-min-zu-da-xue-tu-shu-guan-zui-xin-xiao-xi}

<Route author="real-jiakai" example="/gxmzu/libzxxx" path="/gxmzu/libzxxx" radar="1" />

## 广州大学 {#guang-zhou-da-xue}

### 研究生院招生动态 {#guang-zhou-da-xue-yan-jiu-sheng-yuan-zhao-sheng-dong-tai}
Expand Down
Loading