rsshub
Version:
Make RSS Great Again!
74 lines (72 loc) • 2.55 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { t as invalid_parameter_default } from "./invalid-parameter-rr4AgGpp.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/cnjxol/index.ts
init_esm_shims();
const categories = {
jxrb: "嘉兴日报",
nhwb: "南湖晚报"
};
const route = {
path: "/:category?/:id?",
name: "Unknown",
maintainers: [],
handler
};
async function handler(ctx) {
const category = ctx.req.param("category") ?? "jxrb";
const id = ctx.req.param("id");
if (!Object.keys(categories).includes(category)) throw new invalid_parameter_default("Invalid category");
const currentUrl = `${`https://${category}.cnjxol.com`}/${category}Paper/pc/layout`;
let $ = load((await got_default({
method: "get",
url: currentUrl
})).data);
const dateMatch = $("a").first().attr("href").match(/\d{6}\/\d{2}/)[0];
let items = [];
if (id) {
$ = load((await got_default({
method: "get",
url: `${currentUrl}/${dateMatch}/node_${id}.html`
})).data);
items = $("#articlelist .clearfix a").toArray().map((a) => `${currentUrl}/${$(a).attr("href")}`.replaceAll("layout/../../../", ""));
} else await Promise.all($("#list li a").toArray().map(async (p) => {
const page = load((await got_default({
method: "get",
url: `${currentUrl}/${$(p).attr("href")}`
})).data);
items.push(...page("#articlelist .clearfix a").toArray().map((a) => `${currentUrl}/${page(a).attr("href")}`.replaceAll("layout/../../../", "")));
}));
items = await Promise.all(items.map((item) => cache_default.tryGet(item, async () => {
const content = load((await got_default({
method: "get",
url: item
})).data);
return {
link: item,
title: content("#Title").text(),
pubDate: parseDate(content("date").text()),
description: art(path.join(__dirname, "templates/description-b24e1338.art"), {
attachment: content(".attachment").html(),
content: content("founder-content").html()
})
};
})));
return {
title: `${categories[category]}${id ? ` - ${$("#layout").text()}` : ""}`,
link: currentUrl,
item: items
};
}
//#endregion
export { route };