From 7a1a9b2cf789368d451d377627fd899bdf1a9b27 Mon Sep 17 00:00:00 2001 From: linsenwang <88711203+linsenwang@users.noreply.github.com> Date: Wed, 15 Jan 2025 11:04:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=8E=A6=E9=97=A8?= =?UTF-8?q?=E5=A4=A7=E5=AD=A6=E7=BB=8F=E6=B5=8E=E5=AD=A6=E9=99=A2=E7=A7=91?= =?UTF-8?q?=E7=A0=94=E5=8A=A8=E6=80=81=20(#18126)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add 厦门大学经济学院科研动态 * Apply suggestions from code review Thanks for the feedback! The change has been applied. Co-authored-by: Tony --------- --- lib/routes/xmu/kydt.ts | 68 +++++++++++++++++++++++++++++++++++++ lib/routes/xmu/namespace.ts | 9 +++++ 2 files changed, 77 insertions(+) create mode 100644 lib/routes/xmu/kydt.ts create mode 100644 lib/routes/xmu/namespace.ts diff --git a/lib/routes/xmu/kydt.ts b/lib/routes/xmu/kydt.ts new file mode 100644 index 00000000000000..ac6c0be51cedf8 --- /dev/null +++ b/lib/routes/xmu/kydt.ts @@ -0,0 +1,68 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; +import cache from '@/utils/cache'; + +export const route: Route = { + path: '/kydt', + categories: ['university'], + example: '/xmu/kydt', + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['soe.xmu.edu.cn/kxyj/kydt.htm'], + }, + ], + name: '科研动态', + maintainers: ['linsenwang'], + handler, +}; + +async function handler() { + const host = 'https://soe.xmu.edu.cn/kxyj/kydt.htm'; + const response = await ofetch(host); + const $ = load(response); + + const list = $('div.news li') + .toArray() + .map((item) => { + item = $(item); + const title = item.find('h4').first().text(); + const time = item.find('h6').first().text(); + const a = item.find('a').first().attr('href'); + const fullUrl = new URL(a, host).href; + + return { + title, + link: fullUrl, + pubDate: time, + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await ofetch(item.link); + const $ = load(response); + + item.description = $('.v_news_content').first().html(); + + return item; + }) + ) + ); + + return { + allowEmpty: true, + title: '厦门大学经济学院科研动态', + link: host, + item: items, + }; +} diff --git a/lib/routes/xmu/namespace.ts b/lib/routes/xmu/namespace.ts new file mode 100644 index 00000000000000..c5725efa5d0d99 --- /dev/null +++ b/lib/routes/xmu/namespace.ts @@ -0,0 +1,9 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Xiamen University', + url: 'soe.xmu.edu.cn', + zh: { + name: '厦门大学经济学院', + }, +};