Skip to content

Commit

Permalink
feat(route): add 长江大学动物科学学院 (#12795)
Browse files Browse the repository at this point in the history
  • Loading branch information
nczitzk committed Jul 13, 2023
1 parent e03f0b8 commit 24c679a
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,22 @@ pageClass: routes

<Route author="nczitzk" example="/bupt/rczp" path="/bupt/rczp" />

## 长江大学

### 动物科学学院

<Route author="nczitzk" example="/yangtzeu/dongke" path="/yangtzeu/dongke/:path+" :paramsDesc="['路径,默认为学院新闻']">

::: tip 提示

若订阅 [院情总览 - 通知公告](https://dongke.yangtzeu.edu.cn/yqzl/tzgg.htm),网址为 <https://dongke.yangtzeu.edu.cn/yqzl/tzgg.htm>。截取 `https://dongke.yangtzeu.edu.cn` 到末尾 `.htm` 的部分 `/yqzl/tzgg` 作为参数,此时路由为 [`/yangtzeu/dongke/yqzl/tzgg`](https://rsshub.app/yangtzeu/dongke/yqzl/tzgg)

若订阅子分类 [学生工作](https://dongke.yangtzeu.edu.cn/xsgz.htm),网址为 <https://dongke.yangtzeu.edu.cn/xsgz.htm>。截取 `https://dongke.yangtzeu.edu.cn` 到末尾 `.htm` 的部分 `/xsgz` 作为参数,此时路由为 [`/yangtzeu/dongke/xsgz`](https://rsshub.app/yangtzeu/dongke/xsgz)

:::

</Route>

## 常州大学

### 教务处
Expand Down
60 changes: 60 additions & 0 deletions lib/v2/yangtzeu/dongke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 10;

const rootUrl = 'https://dongke.yangtzeu.edu.cn';
const currentUrl = new URL(`${ctx.path.replace(/^\/dongke/, '') || '/yqzl/xyxw'}.htm`, rootUrl).href;

const { data: response } = await got(currentUrl);

const $ = cheerio.load(response);

let items = $('ul.list-item li a')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);

return {
title: item.text(),
link: new URL(item.prop('href'), rootUrl).href,
};
});

items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: detailResponse } = await got(item.link);

const content = cheerio.load(detailResponse);

item.title = content('title').text();
item.description = content('div.v_news_content').html();
item.category = content('meta[name="keywords"]').prop('content').split(',');
item.pubDate = timezone(
parseDate(
content('p.content-info')
.text()
.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/)[1]
),
+8
);

return item;
})
)
);

ctx.state.data = {
item: items,
title: $('title').text(),
link: currentUrl,
language: 'zh-cn',
image: new URL($('#head-img a img').prop('src'), rootUrl).href,
author: '长江大学动物科学学院',
};
};
3 changes: 3 additions & 0 deletions lib/v2/yangtzeu/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/dongke/:path+': ['nczitzk'],
};
18 changes: 18 additions & 0 deletions lib/v2/yangtzeu/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
'yangtzeu.edu.cn': {
_name: '长江大学',
'.': [
{
title: '动物科学学院',
docs: 'https://docs.rsshub.app/universities.html#chang-jiang-da-xue-dong-wu-ke-xue-xue-yuan',
source: ['/:category', '/'],
target: (params, url) => {
url = new URL(url);
const path = /\.edu\.cn(.*?)\.htm/.test(url.href) ? url.href.match(/\.edu\.cn(.*?)\.htm/)[1] : '';

return `/yangtzeu/dongke${path}`;
},
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/yangtzeu/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get(/dongke([\w-/]+)?/, require('./dongke'));
};

0 comments on commit 24c679a

Please sign in to comment.