From b2ef174ebe5664d555899da74c24a4c338cafa8e Mon Sep 17 00:00:00 2001 From: Chikit-L <57130625+Chikit-L@users.noreply.github.com> Date: Fri, 8 Nov 2024 23:00:38 +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=E7=A7=91=E5=AD=A6=E9=99=A2=E7=A0=94=E7=A9=B6?= =?UTF-8?q?=E7=94=9F=E9=99=A2=20(#17458)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 新增 中国地质科学院研究生院 路由 * feat(route): add 中国地质科学院研究生院 * Update namespace.ts * feat(route): add 中国地质科学院研究生院 --- lib/routes/cags/edu/index.ts | 84 ++++++++++++++++++++++++++++++++++++ lib/routes/cags/namespace.ts | 9 ++++ 2 files changed, 93 insertions(+) create mode 100644 lib/routes/cags/edu/index.ts create mode 100644 lib/routes/cags/namespace.ts diff --git a/lib/routes/cags/edu/index.ts b/lib/routes/cags/edu/index.ts new file mode 100644 index 000000000..f5e71ed6d --- /dev/null +++ b/lib/routes/cags/edu/index.ts @@ -0,0 +1,84 @@ +import ofetch from '@/utils/ofetch'; +import { Route } from '@/types'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; + +const host = 'https://edu.cags.ac.cn'; + +const titles = { + tzgg: '通知公告', + ywjx: '要闻简讯', + zs_bss: '博士生招生', + zs_sss: '硕士生招生', + zs_dxsxly: '大学生夏令营', +}; + +export const route: Route = { + path: '/edu/:category', + categories: ['university'], + example: '/cags/edu/tzgg', + parameters: { + category: '通知频道,可选 tzgg/ywjx/zs_bss/zs_sss/zs_dxsxly', + }, + features: { + antiCrawler: false, + requireConfig: false, + requirePuppeteer: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '研究生院', + maintainers: ['Chikit-L'], + radar: [ + { + source: ['edu.cags.ac.cn/'], + }, + ], + handler, + description: ` +| 通知公告 | 要闻简讯 | 博士生招生 | 硕士生招生 | 大学生夏令营 | +| -------- | -------- | ---------- | ---------- | ------------ | +| tzgg | ywjx | zs_bss | zs_sss | zs_dxsxly | +`, +}; + +async function handler(ctx) { + const category = ctx.req.param('category'); + const title = titles[category]; + + if (!title) { + throw new Error(`Invalid category: ${category}`); + } + + const API_URL = `${host}/api/cms/cmsNews/pageByCmsNavBarId/${category}/1/10/0`; + const response = await ofetch(API_URL); + const data = response.data; + + const items = data.map((item) => { + const id = item.id; + const title = item.title; + + let pubDate = null; + if (item.publishDate) { + pubDate = parseDate(item.publishDate, 'YYYY-MM-DD'); + pubDate = timezone(pubDate, 8); + } + + const link = `${host}/#/dky/view/id=${id}/barId=${category}`; + + return { + title, + description: item.introduction, + link, + guid: link, + pubDate, + }; + }); + + return { + title, + link: `${host}/#/dky/list/barId=${category}/cmsNavCategory=1`, + item: items, + }; +} diff --git a/lib/routes/cags/namespace.ts b/lib/routes/cags/namespace.ts new file mode 100644 index 000000000..abb34c06b --- /dev/null +++ b/lib/routes/cags/namespace.ts @@ -0,0 +1,9 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Chinese Academy of Geological Sciences', + url: 'cags.cgs.gov.cn', + zh: { + name: '中国地质科学院', + }, +};