From 6d77bd84c0aa356e0f580087a652e1139216bd6d Mon Sep 17 00:00:00 2001 From: Hi <41277925+syncmeta@users.noreply.github.com> Date: Thu, 9 Jul 2026 23:28:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=AD=E5=9B=BD?= =?UTF-8?q?=E5=9C=B0=E8=B4=A8=E5=A4=A7=E5=AD=A6=EF=BC=88=E5=8C=97=E4=BA=AC?= =?UTF-8?q?=EF=BC=89=20(#22352)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * route: add 中国地质大学(北京) Co-Authored-By: Claude * feat(route): add channel icon for 中国地质大学(北京) Co-Authored-By: Claude * fix(route): use official crest favicon as 中国地质大学(北京)feed icon Co-Authored-By: Claude * fix(route): use official high-res crest for 中国地质大学(北京)feed icon Co-Authored-By: Claude --------- Co-authored-by: Claude --- lib/routes/cugb/jwc.ts | 81 +++++++++++++++++++++++++++++++++ lib/routes/cugb/namespace.ts | 13 ++++++ lib/routes/cugb/news.ts | 86 ++++++++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 lib/routes/cugb/jwc.ts create mode 100644 lib/routes/cugb/namespace.ts create mode 100644 lib/routes/cugb/news.ts diff --git a/lib/routes/cugb/jwc.ts b/lib/routes/cugb/jwc.ts new file mode 100644 index 000000000..1c39123b2 --- /dev/null +++ b/lib/routes/cugb/jwc.ts @@ -0,0 +1,81 @@ +import { load } from 'cheerio'; + +import type { Data, DataItem, Route } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; + +const rootUrl = 'https://jwc.cugb.edu.cn'; + +const channels: Record = { + xszq: '学生专区', +}; + +export const route: Route = { + path: '/jwc/:channel?', + categories: ['university'], + example: '/cugb/jwc/xszq', + parameters: { channel: '栏目,默认为 `xszq` 学生专区' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['jwc.cugb.edu.cn/:channel'], + target: '/jwc/:channel', + }, + ], + name: '教务处', + maintainers: ['syncmeta'], + handler, +}; + +async function handler(ctx): Promise { + const channel = ctx.req.param('channel') ?? 'xszq'; + const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 20; + const listUrl = `${rootUrl}/${channel}/`; + + const { data: response } = await got(listUrl); + const $ = load(response); + + const list: DataItem[] = $('li a') + .toArray() + .map((el) => { + const item = $(el); + const title = item.find('.list_con_main').text().trim(); + return { + title, + link: new URL(item.attr('href') as string, rootUrl).href, + pubDate: timezone(parseDate(item.find('.list_con_time').text().trim()), 8), + }; + }) + .filter((item) => item.title) + .slice(0, limit); + + const items = (await Promise.all( + list.map((item) => + cache.tryGet(item.link as string, async () => { + const { data: detailResponse } = await got(item.link as string); + const content = load(detailResponse); + item.description = content('div.detail_content_box').html() ?? ''; + return item; + }) + ) + )) as DataItem[]; + + return { + title: `中国地质大学(北京)教务处 - ${channels[channel] ?? channel}`, + link: listUrl, + item: items, + language: 'zh-CN', + image: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png', + icon: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png', + logo: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png', + }; +} diff --git a/lib/routes/cugb/namespace.ts b/lib/routes/cugb/namespace.ts new file mode 100644 index 000000000..64549ef26 --- /dev/null +++ b/lib/routes/cugb/namespace.ts @@ -0,0 +1,13 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'China University of Geosciences (Beijing)', + url: 'cugb.edu.cn', + categories: ['university'], + description: '', + lang: 'zh-CN', + + zh: { + name: '中国地质大学(北京)', + }, +}; diff --git a/lib/routes/cugb/news.ts b/lib/routes/cugb/news.ts new file mode 100644 index 000000000..792e63c56 --- /dev/null +++ b/lib/routes/cugb/news.ts @@ -0,0 +1,86 @@ +import { load } from 'cheerio'; + +import type { Data, DataItem, Route } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; + +const rootUrl = 'https://www.cugb.edu.cn'; + +const channels: Record = { + bdxw: '北地新闻', +}; + +export const route: Route = { + path: '/news/:channel?', + categories: ['university'], + example: '/cugb/news/bdxw', + parameters: { channel: '栏目,默认为 `bdxw` 北地新闻' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['www.cugb.edu.cn/:channel.jhtml'], + target: '/news/:channel', + }, + ], + name: '校园新闻', + maintainers: ['syncmeta'], + handler, +}; + +async function handler(ctx): Promise { + const channel = ctx.req.param('channel') ?? 'bdxw'; + const limit = ctx.req.query('limit') ? Number(ctx.req.query('limit')) : 20; + const listUrl = `${rootUrl}/${channel}.jhtml`; + + const { data: response } = await got(listUrl); + const $ = load(response); + + const list: DataItem[] = $('li a.con') + .toArray() + .slice(0, limit) + .map((el) => { + const item = $(el); + const [date, author] = item + .find('span') + .text() + .trim() + .split('|') + .map((s) => s.trim()); + return { + title: item.find('h3.tit').text().trim(), + link: new URL(item.attr('href') as string, rootUrl).href, + pubDate: timezone(parseDate(date), 8), + author, + }; + }); + + const items = (await Promise.all( + list.map((item) => + cache.tryGet(item.link as string, async () => { + const { data: detailResponse } = await got(item.link as string); + const content = load(detailResponse); + item.description = content('div.postbody').html() ?? ''; + return item; + }) + ) + )) as DataItem[]; + + return { + title: `中国地质大学(北京) - ${channels[channel] ?? channel}`, + link: listUrl, + item: items, + language: 'zh-CN', + image: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png', + icon: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png', + logo: 'https://bm.cugb.edu.cn/vis/images/xhgf/logo.png', + }; +}