feat:增加临沂大学校园新闻RSS (#5054) (#5580)

Signed-off-by: ueiu <bautuoyoul@gmail.com>
This commit is contained in:
ueiu
2020-09-02 19:49:41 +01:00
committed by GitHub
parent 4a84851c73
commit 0740a651bc
4 changed files with 97 additions and 0 deletions
+11
View File
@@ -843,6 +843,17 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS
<Route author="ikvarxt" example="/lntu/jwnews" path="/lntu/jwnews" />
## 临沂大学
### 新闻
<Route author="ueiu" example="/lyu/news/ldyw" path="/lyu/news/:type" :paramsDesc="['分类名']">
| 临大要闻 | 信息公告 |
| -------- | -------- |
| ldyw | xxgg |
</Route>
## 洛阳理工学院
### 教务处
+3
View File
@@ -840,6 +840,9 @@ router.get('/ahut/cstzgg', require('./routes/universities/ahut/cstzgg'));
// 上海理工大学
router.get('/usst/jwc', require('./routes/universities/usst/jwc'));
// 临沂大学
router.get('/lyu/news/:type', require('./routes/universities/lyu/news/index'));
// ifanr
router.get('/ifanr/:channel?', require('./routes/ifanr/index'));
+40
View File
@@ -0,0 +1,40 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const util = require('./utils');
const baseUrl = 'https://www.lyu.edu.cn/';
module.exports = async (ctx) => {
const type = ctx.params.type;
let title, path;
switch (type) {
case 'ldyw':
title = '临大要闻';
path = '8125';
break;
case 'xxgg':
title = '信息公告';
path = '8126';
break;
}
// 完整url
const fullUrl = baseUrl + path + '/list.htm';
const response = await got({
method: 'get',
url: fullUrl,
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('.column-news-item').get();
const result = await util.ProcessFeed(baseUrl, list, ctx.cache);
ctx.state.data = {
title: '临沂大学 - ' + title,
link: fullUrl,
description: '临沂大学 - ' + title,
item: result,
};
};
+43
View File
@@ -0,0 +1,43 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
// 获取完整文章内容
async function load(link) {
const response = await got.get(link);
const $ = cheerio.load(response.data);
// 提取内容
const description = $('.wp-container').html();
// 返回结果
return { description };
}
const ProcessFeed = async (baseUrl, list, caches) =>
// 使用 Promise.all() 进行 async 并发
await Promise.all(
// 遍历每一篇文章
list.map(async (item) => {
const $ = cheerio.load(item);
// 还原相对链接为绝对链接
const itemUrl = url.resolve(baseUrl, $('a').attr('href'));
// 提取列表信息
const single = {
title: $('.column-news-title').text(),
link: itemUrl,
author: '临沂大学',
pubDate: new Date($('.news-date-hide').text()).toUTCString(),
guid: itemUrl,
};
// 使用tryGet方法从缓存获取内容。
// 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。
const other = await caches.tryGet(itemUrl, async () => await load(itemUrl));
// 合并解析后的结果集作为该篇文章最终的输出结果
return Promise.resolve(Object.assign({}, single, other));
})
);
module.exports = {
ProcessFeed,
};