From 82cbe3cc7e725458065c9897af663b5a610eb4b2 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:52:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=B9=96=E5=8C=97?= =?UTF-8?q?=E5=A4=A7=E5=AD=A6=E8=B5=84=E6=BA=90=E7=8E=AF=E5=A2=83=E5=AD=A6?= =?UTF-8?q?=E9=99=A2=20(#15050)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 湖北大学资源环境学院 * fix typo * fix radar --- lib/routes/hubu/index.ts | 124 +++++++++++++++++++ lib/routes/hubu/namespace.ts | 8 ++ lib/routes/hubu/zhxy.ts | 228 +++++++++++++++++++++++++++++++++++ 3 files changed, 360 insertions(+) create mode 100644 lib/routes/hubu/index.ts create mode 100644 lib/routes/hubu/namespace.ts create mode 100644 lib/routes/hubu/zhxy.ts diff --git a/lib/routes/hubu/index.ts b/lib/routes/hubu/index.ts new file mode 100644 index 000000000..3b87dfd62 --- /dev/null +++ b/lib/routes/hubu/index.ts @@ -0,0 +1,124 @@ +import { Route } from '@/types'; + +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; + +export const handler = async (ctx) => { + const { category = 'index/tzgg' } = ctx.req.param(); + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20; + + const rootUrl = 'https://www.hubu.edu.cn'; + const currentUrl = new URL(`${category}.htm`, rootUrl).href; + + const { data: response } = await got(currentUrl); + + const $ = load(response); + + const language = $('html').prop('lang'); + + let items = $('div.list ul li') + .slice(0, limit) + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.find('a').text(), + pubDate: parseDate(item.find('span').text()), + link: new URL(item.find('a').prop('href'), rootUrl).href, + language, + }; + }); + + items = await Promise.all( + items.map((item) => + cache.tryGet(item.link, async () => { + try { + const { data: detailResponse } = await got(item.link); + + const $$ = load(detailResponse); + + const title = $$('div.con-tit h4').text(); + + if (!title) { + return item; + } + + const description = $$('div.v_news_content').html(); + + item.title = title; + item.description = description; + item.category = $$('META[Name="keywords"]') + .toArray() + .map((c) => $$(c).text()); + item.content = { + html: description, + text: $$('div.v_news_content').text(), + }; + item.language = language; + } catch { + // no-empty + } + + return item; + }) + ) + ); + + const title = $('title').text(); + const image = new URL($('div.logo a img').prop('src'), rootUrl).href; + + return { + title, + description: $('META[Name="keywords"]').prop('content'), + link: currentUrl, + item: items, + allowEmpty: true, + image, + author: title.split(/-/).pop(), + language, + }; +}; + +export const route: Route = { + path: '/www/:category{.+}?', + name: '主页', + url: 'hubu.edu.cn', + maintainers: ['nczitzk'], + handler, + example: '/hubu/www/index/tzgg', + parameters: { category: '分类,可在对应分类页 URL 中找到,默认为[通知公告](https://www.hubu.edu.cn/index/tzgg.htm)' }, + description: `:::tip + 若订阅 [通知公告](https://www.hubu.edu.cn/index/tzgg.htm),网址为 \`https://www.hubu.edu.cn/index/tzgg.htm\`。截取 \`https://www.hubu.edu.cn/\` 到末尾 \`.htm\` 的部分 \`index/tzgg\` 作为参数填入,此时路由为 [\`/hubu/www/index/tzgg\`](https://rsshub.app/hubu/www/index/tzgg)。 + ::: + + | 通知公告 | 学术预告 | + | ---------- | ---------- | + | index/tzgg | index/xsyg | + `, + categories: ['university'], + + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportRadar: true, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + title: '通知公告', + source: ['hubu.edu.cn/index/tzgg.htm'], + target: '/www/index/tzgg', + }, + { + title: '学术预告', + source: ['hubu.edu.cn/index/xsyg.htm'], + target: '/www/index/xsyg', + }, + ], +}; diff --git a/lib/routes/hubu/namespace.ts b/lib/routes/hubu/namespace.ts new file mode 100644 index 000000000..185d6e729 --- /dev/null +++ b/lib/routes/hubu/namespace.ts @@ -0,0 +1,8 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '湖北大学', + url: 'hubu.edu.cn', + categories: ['university'], + description: '', +}; diff --git a/lib/routes/hubu/zhxy.ts b/lib/routes/hubu/zhxy.ts new file mode 100644 index 000000000..3f8e61a76 --- /dev/null +++ b/lib/routes/hubu/zhxy.ts @@ -0,0 +1,228 @@ +import { Route } from '@/types'; + +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; + +export const handler = async (ctx) => { + const { category = 'index/tzgg' } = ctx.req.param(); + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20; + + const rootUrl = 'https://zhxy.hubu.edu.cn'; + const currentUrl = new URL(`${category}.htm`, rootUrl).href; + + const { data: response } = await got(currentUrl); + + const $ = load(response); + + const language = $('html').prop('lang'); + + let items = $('div.box h1 a') + .slice(0, limit) + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.contents().first().text(), + pubDate: parseDate(item.find('span').text().replaceAll('[]', '')), + link: new URL(item.prop('href'), currentUrl).href, + language, + }; + }); + + items = await Promise.all( + items.map((item) => + cache.tryGet(item.link, async () => { + try { + const { data: detailResponse } = await got(item.link); + + const $$ = load(detailResponse); + + const title = $$('div.ar_title h1').text(); + + if (!title) { + return item; + } + + const description = $$('div.v_news_content').html(); + + item.title = title; + item.description = description; + item.category = $$('META[Name="keywords"]') + .toArray() + .map((c) => $$(c).text()); + item.content = { + html: description, + text: $$('div.v_news_content').text(), + }; + item.language = language; + } catch { + // no-empty + } + + return item; + }) + ) + ); + + const title = $('title').text(); + const image = new URL($('div.logo a img').prop('src'), currentUrl).href; + + return { + title, + description: $('META[Name="keywords"]').prop('content'), + link: currentUrl, + item: items, + allowEmpty: true, + image, + author: title.split(/-/).pop(), + language, + }; +}; + +export const route: Route = { + path: '/zhxy/:category{.+}?', + name: '资源环境学院', + url: 'zhxy.hubu.edu.cn', + maintainers: ['nczitzk'], + handler, + example: '/hubu/zhxy/index/tzgg', + parameters: { category: '分类,可在对应分类页 URL 中找到,默认为[通知公告](https://zhxy.hubu.edu.cn/index/tzgg.htm)' }, + description: `:::tip + 若订阅 [通知公告](https://zhxy.hubu.edu.cn/index/tzgg.htm),网址为 \`https://zhxy.hubu.edu.cn/index/tzgg.htm\`。截取 \`https://zhxy.hubu.edu.cn/\` 到末尾 \`.htm\` 的部分 \`index/tzgg\` 作为参数填入,此时路由为 [\`/hubu/zhxy/index/tzgg\`](https://rsshub.app/hubu/zhxy/index/tzgg)。 + ::: + + | [通知公告](https://zhxy.hubu.edu.cn/index/tzgg.htm) | [新闻动态](https://zhxy.hubu.edu.cn/index/xwdt.htm) | + | --------------------------------------------------- | --------------------------------------------------- | + | index/tzgg | index/xwdt | + + #### [人才培养](https://zhxy.hubu.edu.cn/rcpy.htm) + + | [人才培养](https://zhxy.hubu.edu.cn/rcpy.htm) | [本科生教育](https://zhxy.hubu.edu.cn/rcpy/bksjy.htm) | [研究生教育](https://zhxy.hubu.edu.cn/rcpy/yjsjy.htm) | [招生与就业](https://zhxy.hubu.edu.cn/rcpy/zsyjy/zsxx.htm) | + | --------------------------------------------- | ----------------------------------------------------- | ----------------------------------------------------- | ---------------------------------------------------------- | + | rcpy | rcpy/bksjy | rcpy/yjsjy | rcpy/zsyjy/zsxx | + + #### [学科建设](https://zhxy.hubu.edu.cn/xkjianshe/zdxk.htm) + + | [学科建设](https://zhxy.hubu.edu.cn/xkjianshe/zdxk.htm) | [重点学科](https://zhxy.hubu.edu.cn/xkjianshe/zdxk.htm) | [硕士点](https://zhxy.hubu.edu.cn/xkjianshe/ssd.htm) | [博士点](https://zhxy.hubu.edu.cn/xkjianshe/bsd.htm) | + | ------------------------------------------------------- | ------------------------------------------------------- | ---------------------------------------------------- | ---------------------------------------------------- | + | xkjianshe/zdxk | xkjianshe/zdxk | xkjianshe/ssd | xkjianshe/bsd | + + #### [科研服务](https://zhxy.hubu.edu.cn/kyfw.htm) + + | [科研服务](https://zhxy.hubu.edu.cn/kyfw.htm) | [科研动态](https://zhxy.hubu.edu.cn/kyfw/kydongt.htm) | [学术交流](https://zhxy.hubu.edu.cn/kyfw/xsjl.htm) | [科研平台](https://zhxy.hubu.edu.cn/kyfw/keyapt.htm) | [社会服务](https://zhxy.hubu.edu.cn/kyfw/shfuw.htm) | + | --------------------------------------------- | ----------------------------------------------------- | -------------------------------------------------- | ---------------------------------------------------- | --------------------------------------------------- | + | kyfw | kyfw/kydongt | kyfw/xsjl | kyfw/keyapt | kyfw/shfuw | + + #### [党群工作](https://zhxy.hubu.edu.cn/dqgz.htm) + + | [党群工作](https://zhxy.hubu.edu.cn/dqgz.htm) | [党建工作](https://zhxy.hubu.edu.cn/dqgz/djgz/jgdj.htm) | [工会工作](https://zhxy.hubu.edu.cn/dqgz/ghgon.htm) | + | --------------------------------------------- | ------------------------------------------------------- | --------------------------------------------------- | + | dqgz | dqgz/djgz/jgdj | dqgz/ghgon | + `, + categories: ['university'], + + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportRadar: true, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + title: '通知公告', + source: ['zhxy.hubu.edu.cn/index/tzgg.htm'], + target: '/zhxy/index/tzgg', + }, + { + title: '新闻动态', + source: ['zhxy.hubu.edu.cn/index/xwdt.htm'], + target: '/zhxy/index/xwdt', + }, + { + title: '人才培养', + source: ['zhxy.hubu.edu.cn/rcpy.htm'], + target: '/zhxy/rcpy', + }, + { + title: '人才培养 - 本科生教育', + source: ['zhxy.hubu.edu.cn/rcpy/bksjy.htm'], + target: '/zhxy/rcpy/bksjy', + }, + { + title: '人才培养 - 研究生教育', + source: ['zhxy.hubu.edu.cn/rcpy/yjsjy.htm'], + target: '/zhxy/rcpy/yjsjy', + }, + { + title: '人才培养 - 招生与就业', + source: ['zhxy.hubu.edu.cn/rcpy/zsyjy/zsxx.htm'], + target: '/zhxy/rcpy/zsyjy/zsxx', + }, + { + title: '学科建设', + source: ['zhxy.hubu.edu.cn/xkjianshe/zdxk.htm'], + target: '/zhxy/xkjianshe/zdxk', + }, + { + title: '学科建设 - 重点学科', + source: ['zhxy.hubu.edu.cn/xkjianshe/zdxk.htm'], + target: '/zhxy/xkjianshe/zdxk', + }, + { + title: '学科建设 - 硕士点', + source: ['zhxy.hubu.edu.cn/xkjianshe/ssd.htm'], + target: '/zhxy/xkjianshe/ssd', + }, + { + title: '学科建设 - 博士点', + source: ['zhxy.hubu.edu.cn/xkjianshe/bsd.htm'], + target: '/zhxy/xkjianshe/bsd', + }, + { + title: '科研服务', + source: ['zhxy.hubu.edu.cn/kyfw.htm'], + target: '/zhxy/kyfw', + }, + { + title: '科研服务 - 科研动态', + source: ['zhxy.hubu.edu.cn/kyfw/kydongt.htm'], + target: '/zhxy/kyfw/kydongt', + }, + { + title: '科研服务 - 学术交流', + source: ['zhxy.hubu.edu.cn/kyfw/xsjl.htm'], + target: '/zhxy/kyfw/xsjl', + }, + { + title: '科研服务 - 科研平台', + source: ['zhxy.hubu.edu.cn/kyfw/keyapt.htm'], + target: '/zhxy/kyfw/keyapt', + }, + { + title: '科研服务 - 社会服务', + source: ['zhxy.hubu.edu.cn/kyfw/shfuw.htm'], + target: '/zhxy/kyfw/shfuw', + }, + { + title: '党群工作', + source: ['zhxy.hubu.edu.cn/dqgz.htm'], + target: '/zhxy/dqgz', + }, + { + title: '党群工作 - 党建工作', + source: ['zhxy.hubu.edu.cn/dqgz/djgz/jgdj.htm'], + target: '/zhxy/dqgz/djgz/jgdj', + }, + { + title: '党群工作 - 工会工作', + source: ['zhxy.hubu.edu.cn/dqgz/ghgon.htm'], + target: '/zhxy/dqgz/ghgon', + }, + ], +};