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

[pull] master from diygod:master #986

Merged
merged 3 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions docs/university.md
Original file line number Diff line number Diff line change
Expand Up @@ -3402,6 +3402,22 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS
<Route author="SettingDust" example="/ynnu/edu/news" path="/ynnu/edu/news" >
</Route>

## 长江大学

### 动物科学学院

<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
8 changes: 4 additions & 4 deletions lib/v2/gov/cac/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ module.exports = async (ctx) => {
.toArray()
.map((item) => {
const href = $(item).attr('href');
if (href && href.startsWith('http://www.cac.gov.cn/')) {
const matchArray = href.match(/http:\/\/www\.cac\.gov\.cn(.*?)\/(A.*?\.htm)/);
if (href && href.match(/(?:http:)?\/\/www\.cac\.gov\.cn(.*?)\/(A.*?\.htm)/)) {
const matchArray = href.match(/(?:http:)?\/\/www\.cac\.gov\.cn(.*?)\/(A.*?\.htm)/);
if (matchArray && matchArray.length > 2) {
const path = matchArray[1];
const htmlName = matchArray[2];
Expand All @@ -41,14 +41,14 @@ module.exports = async (ctx) => {
const completeUrl = pathList.find((item) => item && item.path === path).completeUrl;
const { data: channelResponse } = await got(completeUrl);
const $1 = cheerio.load(channelResponse);
const items = $1('li.clearfix')
const items = $1('div#loadingInfoPage li')
.toArray()
.map((item) => {
const c = $1(item);
const a = c.find('a');
const articleHref = a.attr('href');
const title = a.text();
const date = parseDate(c.find('span.times').text());
const date = parseDate(c.find('.times').text());
return {
link: articleHref,
pubDate: timezone(date),
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'));
};