rsshub
Version:
Make RSS Great Again!
87 lines (85 loc) • 2.53 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import { load } from "cheerio";
//#region lib/routes/neea/jlpt.ts
const handler = async (ctx) => {
const limit = Number.parseInt(ctx.req.query("limit") ?? "30", 10);
const baseUrl = "https://jlpt.neea.cn";
const targetUrl = new URL("index.do", baseUrl).href;
const $ = load(await ofetch_default(targetUrl));
const language = $("html").attr("lang") ?? "zh-CN";
let items = [];
items = $("div.indexcontent a").slice(0, limit).toArray().map((el) => {
const $el = $(el);
const title$1 = $el.text();
const pubDateStr = title$1.match(/(\d{4}-\d{2}-\d{2})/)?.[1];
const linkUrl = $el.attr("href");
const upDatedStr = pubDateStr;
return {
title: title$1,
pubDate: pubDateStr ? parseDate(pubDateStr) : void 0,
link: linkUrl ? new URL(linkUrl, baseUrl).href : void 0,
updated: upDatedStr ? parseDate(upDatedStr) : void 0,
language
};
});
items = (await Promise.all(items.map((item) => {
if (!item.link) return item;
return cache_default.tryGet(item.link, async () => {
const $$ = load(await ofetch_default(item.link));
const processedItem = {
title: $$("div.dvTitle").text(),
description: $$("div.dvContent").html() ?? ""
};
return {
...item,
...processedItem
};
});
}))).filter((_) => true);
const title = $("title").text();
return {
title: `${title.split(/-/).pop()} - ${$("div.indexcontent h1").text()}`,
description: title,
link: targetUrl,
item: items,
allowEmpty: true,
image: $("div.header img").attr("arc") ? new URL($("div.header img").attr("arc"), baseUrl).href : void 0,
author: title.split(/-/)[0],
language,
id: targetUrl
};
};
const route = {
path: "/jlpt",
name: "日本语能力测试 JLPT 通知",
url: "jlpt.neea.cn",
maintainers: ["nczitzk"],
handler,
example: "/neea/jlpt",
parameters: void 0,
description: void 0,
categories: ["study"],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{
source: ["jlpt.neea.cn"],
target: "/jlpt"
}],
view: ViewType.Articles
};
//#endregion
export { handler, route };