rsshub
Version:
Make RSS Great Again!
71 lines (69 loc) • 2.7 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.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/cool18/index.ts
const route = {
path: "/:id?/:type?/:keyword?",
url: "cool18.com",
example: "cool18.com/bbs4",
parameters: {
id: "the name of the bbs",
type: "the type of the post. Can be `home`, `gold` or `threadsearch`. Default: `home`",
keyword: "the keyword to search.",
pageSize: "the number of posts to fetch. If the type is not in search, you can type any words. Default: 10"
},
categories: ["bbs"],
radar: [{
source: ["cool18.com/:id/"],
target: "/:id/:type?/:keyword?"
}],
name: "禁忌书屋",
maintainers: ["nczitzk", "Gabrlie"],
handler,
features: { nsfw: true }
};
async function handler(ctx) {
const { id = "bbs4", type = "home", keyword } = ctx.req.param();
const rootUrl = "https://www.cool18.com/" + id + "/index.php";
const currentUrl = rootUrl + (type === "home" ? "" : type === "gold" ? "?app=forum&act=gold" : `?action=search&act=threadsearch&app=forum&keywords=${keyword}&submit=查询`);
const $ = load(await ofetch_default(currentUrl));
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 20;
const list = type === "home" ? JSON.parse($("script:contains(\"_PageData\")").text().match(/const\s+_PageData\s*=\s*(\[[\s\S]*?]);/)?.[1] || "[]").slice(0, limit).map((item) => ({
title: item.subject,
link: `${rootUrl}?app=forum&act=threadview&tid=${item.tid}`,
pubDate: parseDate(item.dateline, "MM/DD/YY"),
author: item.username,
category: item.type,
description: ""
})) : $("#d_list ul li, #thread_list li, .t_l .t_subject").slice(0, limit).toArray().map((item) => {
const a = $(item).find("a").first();
return {
title: a.text(),
link: `${rootUrl}/${a.attr("href")}`,
pubDate: parseDate($(item).find("i").text(), "MM/DD/YY"),
author: $(item).find("a").last().text(),
category: a.find("span").first().text(),
description: ""
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const preElement = load(await ofetch_default(item.link))("pre");
if (preElement.length > 0) {
const htmlContent = preElement.html();
item.description = htmlContent ? htmlContent.replaceAll(/<font color="#E6E6DD">cool18.com<\/font>/g, "") : "";
}
return item;
})));
return {
title: $("title").text(),
link: currentUrl,
item: items
};
}
//#endregion
export { route };