rsshub
Version:
Make RSS Great Again!
49 lines (48 loc) • 1.97 kB
JavaScript
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs";
import { t as parseDate } from "./parse-date-CjhZE69i.mjs";
import { t as cache_default } from "./cache-CiDoUSLo.mjs";
import { t as timezone } from "./timezone-DE--ze1V.mjs";
import { load } from "cheerio";
//#region lib/routes/uwants/index.ts
const rootUrl = "https://www.uwants.com";
const route = {
path: "/:fid",
categories: ["new-media"],
example: "/uwants/1520",
parameters: { fid: "fid,可在对应板块页的 URL 中找到" },
features: { antiCrawler: true },
name: "版塊",
maintainers: ["nczitzk"],
handler
};
async function handler(ctx) {
const { fid } = ctx.req.param();
const limit = Number(ctx.req.query("limit") ?? "15");
const $ = load(await rofetch(`${rootUrl}/archiver/?fid-${fid}.html`));
const list = $("li a").slice(0, limit).toArray().map((item) => {
const $item = $(item);
return {
title: $item.text(),
link: `${rootUrl}/${$item.attr("href")}`
};
});
const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const content = load((await rofetch(item.link)).replaceAll(/\[(\w+)=([\w#]+)\]/g, "<span style=\"$1: $2;\">").replaceAll(/\[url=(.*?)\]/g, "<a href=\"$1\">").replaceAll(/\[\/(color|size)\]/g, "</span>").replaceAll("[/url]", "</a>").replaceAll(/\[(\w+)\]/g, "<$1>").replaceAll(/\[\/(\w+)\]/g, "</$1>"));
const cite = content("cite");
const date = cite.eq(0).parent().text().match(/\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{2} [AP]M/)?.[0];
return {
title: item.title,
link: `${rootUrl}/viewthread.php?tid=${item.link.match(/tid-(\d+)\.html/)[1]}`,
author: cite.eq(0).text(),
description: content(".archiver_post").html(),
pubDate: date ? timezone(parseDate(date, "YYYY-M-D hh:mm A"), 8) : void 0
};
})));
return {
title: `${$("h1 a").text().replace("查看完整版本: ", "")} - Uwants.com`,
link: `${rootUrl}/forumdisplay.php?fid=${fid}`,
item: items
};
}
//#endregion
export { route };