From c567ee5b940ca582154bbc18f5021d14403f15ff Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Fri, 9 Jun 2023 18:53:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=9C=E5=8C=97?= =?UTF-8?q?=E5=B8=88=E8=8C=83=E5=A4=A7=E5=AD=A6=E7=A0=94=E7=A9=B6=E7=94=9F?= =?UTF-8?q?=E9=99=A2=20(#12641)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 东北师范大学研究生院 * doc: fix typo --- docs/university.md | 16 ++++++++++ lib/v2/nenu/maintainer.js | 3 ++ lib/v2/nenu/radar.js | 13 ++++++++ lib/v2/nenu/router.js | 3 ++ lib/v2/nenu/yjsy.js | 64 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+) create mode 100644 lib/v2/nenu/maintainer.js create mode 100644 lib/v2/nenu/radar.js create mode 100644 lib/v2/nenu/router.js create mode 100644 lib/v2/nenu/yjsy.js diff --git a/docs/university.md b/docs/university.md index 5438cf9e6..4189efb74 100644 --- a/docs/university.md +++ b/docs/university.md @@ -973,6 +973,22 @@ pageClass: routes +## 东北师范大学 + +### 研究生院 + + + +::: tip 提示 + +若订阅 [通知公告](https://yjsy.nenu.edu.cn/tzgg.htm),网址为 。截取 `https://yjsy.nenu.edu.cn/` 到末尾 `.htm` 的部分 `tzgg` 作为参数,此时路由为 [`/nenu/yjsy/tzgg`](https://rsshub.app/nenu/yjsy/tzgg)。 + +若订阅 [校内新闻](https://yjsy.nenu.edu.cn/xwdt/xnxw.htm),网址为 。截取 `https://yjsy.nenu.edu.cn/` 到末尾 `.htm` 的部分 `xwdt/xnxw` 作为参数,此时路由为 [`/nenu/yjsy/xwdt/xnxw`](https://rsshub.app/nenu/yjsy/xwdt/xnxw)。 + +::: + + + ## 东莞理工学院 ### 教务处通知 diff --git a/lib/v2/nenu/maintainer.js b/lib/v2/nenu/maintainer.js new file mode 100644 index 000000000..f053fa28d --- /dev/null +++ b/lib/v2/nenu/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/yjsy/:path+': ['nczitzk'], +}; diff --git a/lib/v2/nenu/radar.js b/lib/v2/nenu/radar.js new file mode 100644 index 000000000..b4f278f89 --- /dev/null +++ b/lib/v2/nenu/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'nenu.edu.cn': { + _name: '东北师范大学', + yjsy: [ + { + title: '研究生院', + docs: 'https://docs.rsshub.app/university.html#dong-bei-shi-fan-da-xue-yan-jiu-sheng-yuan', + source: ['/tzgg.htm', '/'], + target: (params, url) => `/nenu/yjsy${new URL(url).href.match(/\.edu\.cn(.*?)\.htm/)[1]}`, + }, + ], + }, +}; diff --git a/lib/v2/nenu/router.js b/lib/v2/nenu/router.js new file mode 100644 index 000000000..2952506cf --- /dev/null +++ b/lib/v2/nenu/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get(/\/yjsy([\w-/]+)?/, require('./yjsy')); +}; diff --git a/lib/v2/nenu/yjsy.js b/lib/v2/nenu/yjsy.js new file mode 100644 index 000000000..9104ee835 --- /dev/null +++ b/lib/v2/nenu/yjsy.js @@ -0,0 +1,64 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 10; + + const path = ctx.path === '/yjsy' ? '/tzgg' : ctx.path.replace(/^\/yjsy/, ''); + + const rootUrl = 'https://yjsy.nenu.edu.cn'; + const currentUrl = `${rootUrl}${path}.htm`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('a.tit') + .slice(0, limit) + .toArray() + .map((item) => { + item = $(item); + + const link = item.attr('href'); + + return { + title: item.text(), + link: /^http/.test(link) ? link : new URL(link, rootUrl).href, + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + if (/yjsy\.nenu\.edu\.cn/.test(item.link)) { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.title = content('h2').text(); + item.description = content('.v_news_content').html(); + item.pubDate = parseDate( + content('h3') + .text() + .match(/(\d{4}-\d{2}-\d{2})/)[1] + ); + } + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};