From 5430b43464a244a22103879b8314ba7e00dee91d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A9=BA?= Date: Thu, 11 Jul 2024 06:55:38 +0800 Subject: [PATCH] feat(route): add j-test.com (#16141) * feat(route): add j-test.com * deprecate specified syntax --- lib/routes/j-test/namespace.ts | 6 ++++ lib/routes/j-test/news.ts | 64 ++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 lib/routes/j-test/namespace.ts create mode 100644 lib/routes/j-test/news.ts diff --git a/lib/routes/j-test/namespace.ts b/lib/routes/j-test/namespace.ts new file mode 100644 index 00000000000000..d3cbb3c899543e --- /dev/null +++ b/lib/routes/j-test/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '实用日本语鉴定考试(J.TEST)', + url: 'www.j-test.com', +}; diff --git a/lib/routes/j-test/news.ts b/lib/routes/j-test/news.ts new file mode 100644 index 00000000000000..ab102eac10f49b --- /dev/null +++ b/lib/routes/j-test/news.ts @@ -0,0 +1,64 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; + +export const route: Route = { + path: '/news', + name: '公告', + url: 'www.j-test.com', + maintainers: ['kuhahku'], + example: '/j-test/news', + parameters: {}, + categories: ['study'], + features: { + supportRadar: true, + }, + radar: [ + { + source: ['www.j-test.com'], + target: '/news', + }, + ], + handler, + description: '', +}; + +async function handler() { + const baseUrl = 'http://www.j-test.com'; + const response = await ofetch(baseUrl); + const $ = load(response); + + const list = $('#content1 > .center > .col_box1 > .col_body1 > ul > li') + .toArray() + .map((item) => { + const [title, date] = $(item).text().trim().replaceAll(']', '').split(' ['); + const link = new URL($(item).children('a').attr('href')!, baseUrl).href; + const pubDate = timezone(parseDate(date), +8); + return { + title, + link, + pubDate, + description: '', + }; + }); + + const items = await Promise.all( + list.map((item) => + cache.tryGet(item.link, async () => { + const response = await ofetch(item.link); + const $ = load(response); + item.description = $('.content > table').html() ?? ''; + return item; + }) + ) + ); + + return { + title: '实用日本语鉴定考试(J.TEST)公告', + link: baseUrl, + item: items, + }; +}