forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add route for graduacted school of CJLU (China Jiliang U…
…niversity) (DIYgod#17149) * feat(namespace): add namespace for CJLU * feat(route): Add route for graduate school of CJLU 为中国计量大学研究生院添加路由 支持将`教师通知`和`研究生通知`页面转化为 RSS 订阅源 * doc: modify discription of some params 修改参数描述 * fix(radar rule): modify radar rule 修改 radar 规则,以正确提供订阅源 * fix: add exception handling 增加异常处理 * chore: optimize conditional logic 优化判断逻辑 * Update lib/routes/cjlu/yjsy/index.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * fix(radar rule): list all source choices 在 radar 规则中列出全部的类型 修改行尾符为 LF * fix(example): correct example of the route 订正路由的案例 ---------
- Loading branch information
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: 'China Jiliang University', | ||
url: 'www.cjlu.edu.cn', | ||
|
||
zh: { | ||
name: '中国计量大学', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { Route } from '@/types'; | ||
import ofetch from '@/utils/ofetch'; | ||
import { load } from 'cheerio'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import cache from '@/utils/cache'; | ||
import timezone from '@/utils/timezone'; | ||
|
||
const host = 'https://yjsy.cjlu.edu.cn/'; | ||
|
||
const titleMap = new Map([ | ||
['yjstz', '中量大研究生院 —— 研究生通知'], | ||
['jstz', '中量大研究生院 —— 教师通知'], | ||
]); | ||
|
||
export const route: Route = { | ||
path: '/yjsy/:cate', | ||
categories: ['university'], | ||
example: '/cjlu/yjsy/yjstz', | ||
parameters: { | ||
cate: '订阅的类型,支持 yjstz(研究生通知)和 jstz(教师通知)', | ||
}, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportRadar: true, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
radar: [ | ||
{ | ||
title: '研究生通知', | ||
source: ['yjsy.cjlu.edu.cn/index/yjstz/:suffix', 'yjsy.cjlu.edu.cn/index/yjstz.htm'], | ||
target: '/yjsy/yjstz', | ||
}, | ||
{ | ||
title: '教师通知', | ||
source: ['yjsy.cjlu.edu.cn/index/jstz/:suffix', 'yjsy.cjlu.edu.cn/index/jstz.htm'], | ||
target: '/yjsy/jstz', | ||
}, | ||
], | ||
name: '研究生院', | ||
maintainers: ['chrisis58'], | ||
handler, | ||
description: `| 研究生通知 | 教师通知 | | ||
| -------- | -------- | | ||
| yjstz | jstz |`, | ||
}; | ||
|
||
async function handler(ctx) { | ||
const cate = ctx.req.param('cate'); | ||
|
||
const response = await ofetch(`${cate}.htm`, { | ||
baseURL: `${host}/index/`, | ||
responseType: 'text', | ||
}); | ||
|
||
const $ = load(response); | ||
|
||
const list = $('div.grid685.right div.body ul') | ||
.find('li') | ||
.toArray() | ||
.map((element) => { | ||
const item = $(element); | ||
|
||
const a = item.find('a').first(); | ||
|
||
const timeStr = item.find('span').first().text().trim(); | ||
const href = a.attr('href') ?? ''; | ||
const route = href.startsWith('../') ? href.replace(/^\.\.\//, '') : href; | ||
|
||
return { | ||
title: a.attr('title') ?? titleMap.get(cate), | ||
pubDate: timezone(parseDate(timeStr, 'YYYY/MM/DD'), +8), | ||
link: `${host}${route}`, | ||
description: '', | ||
}; | ||
}); | ||
|
||
const items = await Promise.all( | ||
list.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
if (!item.link || item.link === host) { | ||
return item; | ||
} | ||
|
||
const res = await ofetch(item.link, { | ||
responseType: 'text', | ||
}); | ||
const $ = load(res); | ||
|
||
const content = $('#vsb_content').html() ?? ''; | ||
const attachments = $('form[name="_newscontent_fromname"] div ul').html() ?? ''; | ||
|
||
item.description = `${content}<br>${attachments}`; | ||
return item; | ||
}) | ||
) | ||
); | ||
|
||
return { | ||
title: titleMap.get(cate), | ||
link: `https://yjsy.cjlu.edu.cn/index/${cate}.htm`, | ||
item: items, | ||
}; | ||
} |