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 <alterkey@qq.com>
This commit is contained in:
alterkey
2026-02-08 21:30:03 +08:00
committed by GitHub
co-authored by alterk
parent 86a0015096
commit c8be7b6061
4 changed files with 266 additions and 0 deletions
+102
View File
@@ -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,
};
},
};
+80
View File
@@ -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,
};
},
};
+9
View File
@@ -0,0 +1,9 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'Shaanxi Normal University',
url: 'snnu.edu.cn',
zh: {
name: '陕西师范大学',
},
};
+75
View File
@@ -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,
};
},
};