Skip to content

Commit

Permalink
feat(route): add j-test.com (#16141)
Browse files Browse the repository at this point in the history
* feat(route): add j-test.com

* deprecate specified syntax
  • Loading branch information
kuhahku authored Jul 10, 2024
1 parent b49df67 commit 5430b43
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/routes/j-test/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '实用日本语鉴定考试(J.TEST)',
url: 'www.j-test.com',
};
64 changes: 64 additions & 0 deletions lib/routes/j-test/news.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}

0 comments on commit 5430b43

Please sign in to comment.