rsshub
Version:
Make RSS Great Again!
108 lines (106 loc) • 4.06 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./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 "./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 timezone } from "./timezone-D8cuwzTY.mjs";
import path from "node:path";
import { load } from "cheerio";
import iconv from "iconv-lite";
//#region lib/routes/jjwxc/book.ts
init_esm_shims();
const route = {
path: "/book/:id?",
categories: ["reading"],
view: ViewType.Notifications,
example: "/jjwxc/book/7013024",
parameters: { id: "作品 id,可在对应作品页中找到" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
name: "作品章节",
maintainers: ["nczitzk"],
handler
};
async function handler(ctx) {
const id = ctx.req.param("id");
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 100;
const rootUrl = "https://www.jjwxc.net";
const currentUrl = new URL(`onebook.php?novelid=${id}`, rootUrl).href;
const { data: response } = await got_default(currentUrl, { responseType: "buffer" });
const $ = load(iconv.decode(response, "gbk"));
const author = $("meta[name=\"Author\"]").prop("content");
const keywords = $("meta[name=\"Keywords\"]").prop("content").split(/,/);
keywords.pop();
const category = keywords.pop();
let items = $("tr[itemprop=\"chapter\"]").toArray().map((item) => {
item = $(item);
const chapterId = item.find("td").first().text().trim();
const chapterName = item.find("span[itemprop=\"headline\"]").text().trim();
const chapterIntro = item.find("td").eq(2).text().trim();
const chapterUrl = new URL(`onebook.php?novelid=${id}&chapterid=${chapterId}`, rootUrl).href;
const chapterWords = item.find("td[itemprop=\"wordCount\"]").text();
const chapterClicks = item.find("td.chapterclick").text();
const chapterUpdatedTime = item.find("td").last().text().trim();
const isVip = item.find("span[itemprop=\"headline\"] font").last().text() === "[VIP]";
const isLock = item.find("td").eq(1).last().text().trim() === "[锁]";
return {
title: `${chapterName} ${chapterIntro}`,
link: chapterUrl,
description: art(path.join(__dirname, "templates/book-6ec795d5.art"), {
chapterId,
chapterName,
chapterIntro,
chapterUrl,
chapterWords,
chapterClicks,
chapterUpdatedTime
}),
author,
category: [isVip ? "VIP" : void 0, ...category?.split(/\s/) ?? []].filter(Boolean),
guid: `jjwxc-${id}#${chapterId}`,
pubDate: timezone(parseDate(chapterUpdatedTime), 8),
isVip,
isLock
};
});
items.reverse();
items = await Promise.all(items.slice(0, limit).map((item) => item.isLock ? Promise.resolve(item) : cache_default.tryGet(item.link, async () => {
if (!item.isVip) {
const { data: detailResponse } = await got_default(item.link, { responseType: "buffer" });
const content = load(iconv.decode(detailResponse, "gbk"));
content("span.favorite_novel").parent().remove();
item.description += art(path.join(__dirname, "templates/book-6ec795d5.art"), { description: content("div.novelbody").html() });
}
delete item.isVip;
return item;
})));
const logoEl = $("div.logo a img");
const image = `https:${logoEl.prop("src")}`;
const icon = new URL("favicon.ico", rootUrl).href;
return {
item: items,
title: `${logoEl.prop("alt").replace(/logo/, "")} | ${author}${keywords[0]}`,
link: currentUrl,
description: $("span[itemprop=\"description\"]").text(),
language: "zh",
image,
icon,
logo: icon,
subtitle: $("meta[name=\"Description\"]").prop("content"),
author: $("meta[name=\"Author\"]").prop("content")
};
}
//#endregion
export { route };