rsshub
Version:
Make RSS Great Again!
70 lines (69 loc) • 2.31 kB
JavaScript
import { t as cache_default } from "./cache-BkqOokyU.mjs";
import { t as got_default } from "./got-BTowW50G.mjs";
import { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime";
import { load } from "cheerio";
import { renderToString } from "hono/jsx/dom/server";
import iconv from "iconv-lite";
//#region lib/routes/cartoonmad/comic.tsx
const baseUrl = "https://www.cartoonmad.com";
const KEY = "5e585";
const renderChapterImage = (url) => renderToString(/* @__PURE__ */ jsx(ChapterImage, { url }));
const ChapterImage = ({ url }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("img", { src: url }), /* @__PURE__ */ jsx("br", {})] });
const loadContent = (id, { chapter, pages }) => {
let description = "";
for (let page = 1; page <= pages; page++) {
const url = `${baseUrl}/${KEY}/${id}/${chapter}/${String(page).padStart(3, "0")}.jpg`;
description += renderChapterImage(url);
}
return description;
};
const getChapters = (id, list) => Promise.all(list.map((item) => cache_default.tryGet(item.link, () => {
item.description = loadContent(id, item);
return item;
})));
const route = {
path: "/comic/:id",
categories: ["anime"],
example: "/cartoonmad/comic/5827",
parameters: { id: "漫画ID" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["cartoonmad.com/comic/:id"] }],
name: "漫画更新",
maintainers: ["KellyHwong"],
handler
};
async function handler(ctx) {
const id = ctx.req.param("id");
const link = `${baseUrl}/comic/${id}`;
const { data } = await got_default(link, {
responseType: "buffer",
headers: { Referer: "https://www.cartoonmad.com/" }
});
const $ = load(iconv.decode(data, "big5"));
const bookIntro = $("#info").eq(0).find("td").text().trim();
const list = $("#info").eq(1).find("a").toArray().map((item) => {
const $item = $(item);
return {
title: $item.text(),
link: `${baseUrl}${$item.attr("href")}`,
chapter: $item.text().match(/\d+/)[0],
pages: $item.next("font").text().match(/\d+/)[0]
};
}).toReversed();
const chapters = await getChapters(id, list);
return {
title: $("head title").text(),
link,
description: bookIntro,
item: chapters
};
}
//#endregion
export { route };