From c8be7b6061e4bf19a694ed19cdd4cca92b80f907 Mon Sep 17 00:00:00 2001 From: alterkey <95027170+alterkeyy@users.noreply.github.com> Date: Sun, 8 Feb 2026 21:30:03 +0800 Subject: [PATCH] feat(route): add snnu routes (#21088) * feat(route): add snnu routes * fix: use the default UA * Revert "fix: use the default UA" This reverts commit b8a41b98681cac2d0cb83f666f2a7a8cb9f152e2. * fix: use the default UA --------- Co-authored-by: alterk --- lib/routes/snnu/ccs.ts | 102 +++++++++++++++++++++++++++++++++++ lib/routes/snnu/index.ts | 80 +++++++++++++++++++++++++++ lib/routes/snnu/namespace.ts | 9 ++++ lib/routes/snnu/yjs.ts | 75 ++++++++++++++++++++++++++ 4 files changed, 266 insertions(+) create mode 100644 lib/routes/snnu/ccs.ts create mode 100644 lib/routes/snnu/index.ts create mode 100644 lib/routes/snnu/namespace.ts create mode 100644 lib/routes/snnu/yjs.ts diff --git a/lib/routes/snnu/ccs.ts b/lib/routes/snnu/ccs.ts new file mode 100644 index 000000000..7eb0f1cb8 --- /dev/null +++ b/lib/routes/snnu/ccs.ts @@ -0,0 +1,102 @@ +import { load } from 'cheerio'; + +import type { Route } from '@/types'; +import cache from '@/utils/cache'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/ccs/:type?', + categories: ['university'], + example: '/snnu/ccs', + url: 'ccs.snnu.edu.cn', + parameters: { + type: '类型,默认为通知公告 (tzgg),可选学院动态 (news)、学术活动 (xshd)', + }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportRadar: true, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '计算机科学学院', + maintainers: ['alterkeyy'], + radar: [ + { + source: ['ccs.snnu.edu.cn/tzgg/zhgl1.htm'], + target: '/ccs/tzgg', + }, + { + source: ['ccs.snnu.edu.cn/xydt/zhxw1.htm'], + target: '/ccs/news', + }, + { + source: ['ccs.snnu.edu.cn/xssq/xshd.htm'], + target: '/ccs/xshd', + }, + ], + handler: async (ctx) => { + const { type = 'tzgg' } = ctx.req.param(); + const urlMap = { + tzgg: { + url: 'https://ccs.snnu.edu.cn/tzgg/zhgl1.htm', + name: '通知公告', + }, + news: { + url: 'https://ccs.snnu.edu.cn/xydt/zhxw1.htm', + name: '学院动态', + }, + xshd: { + url: 'https://ccs.snnu.edu.cn/xssq/xshd.htm', + name: '学术活动', + }, + }; + + const configTarget = urlMap[type] || urlMap.tzgg; + const response = await ofetch(configTarget.url); + const $ = load(response); + const list = $('.lunwen dl dd').toArray().slice(0, 10); + + const items = await Promise.all( + list.map((item) => { + const $item = $(item); + const $link = $item.find('a').first(); + const link = new URL($link.attr('href') || '', configTarget.url).href; + + const pubDate = parseDate($item.find('.spani').text()); + const title = $link.text(); + + return cache.tryGet(link, async () => { + try { + const detailResponse = await ofetch(link); + const $$ = load(detailResponse); + const description = $$('.v_news_content').html() || $$('#vsb_content').html() || ''; + + return { + title, + link, + description, + pubDate, + }; + } catch { + return { + title, + link, + pubDate, + }; + } + }); + }) + ); + + return { + title: `陕西师范大学 - 计算机科学学院${configTarget.name}`, + link: configTarget.url, + image: 'https://ccs.snnu.edu.cn/images/logo.png', + item: items, + }; + }, +}; diff --git a/lib/routes/snnu/index.ts b/lib/routes/snnu/index.ts new file mode 100644 index 000000000..b50d6704a --- /dev/null +++ b/lib/routes/snnu/index.ts @@ -0,0 +1,80 @@ +import { load } from 'cheerio'; + +import type { Route } from '@/types'; +import cache from '@/utils/cache'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/', + categories: ['university'], + example: '/snnu', + url: 'www.snnu.edu.cn', + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportRadar: true, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '学校官网 - 通知公告', + maintainers: ['alterkeyy'], + radar: [ + { + source: ['www.snnu.edu.cn/tzgg.htm'], + target: '/', + }, + ], + handler: async () => { + const url = 'https://www.snnu.edu.cn/tzgg.htm'; + const response = await ofetch(url); + const $ = load(response); + const list = $('.ul-txtq3 li').toArray().slice(0, 10); + + const items = await Promise.all( + list.map((item) => { + const $item = $(item); + const $link = $item.find('a').first(); + const link = new URL($link.attr('href') || '', url).href; + + const pubDate = parseDate($item.find('.date.date2').first().text()); + + let title = $item.find('a .txt h3').first().text(); + if (!title) { + title = $link.text(); + } + + return cache.tryGet(link, async () => { + try { + const detailResponse = await ofetch(link); + const $$ = load(detailResponse); + const description = $$('.v_news_content').html() || $$('#vsb_content').html() || ''; + + return { + title, + link, + description, + pubDate, + }; + } catch { + // Fallback to title and link if detail fetch fails + return { + title, + link, + pubDate, + }; + } + }); + }) + ); + + return { + title: '陕西师范大学 - 通知公告', + link: url, + image: 'https://www.snnu.edu.cn/images/logo.png', + item: items, + }; + }, +}; diff --git a/lib/routes/snnu/namespace.ts b/lib/routes/snnu/namespace.ts new file mode 100644 index 000000000..6384e50ab --- /dev/null +++ b/lib/routes/snnu/namespace.ts @@ -0,0 +1,9 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Shaanxi Normal University', + url: 'snnu.edu.cn', + zh: { + name: '陕西师范大学', + }, +}; diff --git a/lib/routes/snnu/yjs.ts b/lib/routes/snnu/yjs.ts new file mode 100644 index 000000000..a19425414 --- /dev/null +++ b/lib/routes/snnu/yjs.ts @@ -0,0 +1,75 @@ +import { load } from 'cheerio'; + +import type { Route } from '@/types'; +import cache from '@/utils/cache'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/yjs', + categories: ['university'], + example: '/snnu/yjs', + url: 'newyjs.snnu.edu.cn', + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportRadar: true, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '研究生院通知公告', + maintainers: ['alterkeyy'], + radar: [ + { + source: ['newyjs.snnu.edu.cn/tzgg1.htm'], + target: '/yjs', + }, + ], + handler: async () => { + const url = 'https://newyjs.snnu.edu.cn/tzgg1.htm'; + const response = await ofetch(url); + const $ = load(response); + const list = $('.n_bt li').toArray().slice(0, 10); + + const items = await Promise.all( + list.map((item) => { + const $item = $(item); + const $link = $item.find('a').first(); + const link = new URL($link.attr('href') || '', url).href; + + const pubDate = parseDate($link.find('em').text()); + const title = $link.attr('title') || $link.find('p').text() || $link.text(); + + return cache.tryGet(link, async () => { + try { + const detailResponse = await ofetch(link); + const $$ = load(detailResponse); + const description = $$('.v_news_content').html() || $$('#vsb_content').html() || ''; + + return { + title, + link, + description, + pubDate, + }; + } catch { + return { + title, + link, + pubDate, + }; + } + }); + }) + ); + + return { + title: '陕西师范大学 - 研究生院通知公告', + link: url, + image: 'https://newyjs.snnu.edu.cn/2024html/images24/logo01.png', + item: items, + }; + }, +};