-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add j-test.com (#16141)
* feat(route): add j-test.com * deprecate specified syntax
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |