rsshub
Version:
Make RSS Great Again!
51 lines (49 loc) • 1.73 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 { load } from "cheerio";
//#region lib/routes/chaoli/index.ts
const route = {
path: "/:channel?",
categories: ["bbs"],
example: "/chaoli",
parameters: { channel: "板块,见下表,默认为全部" },
name: "板块",
maintainers: ["nczitzk"],
description: `| 数学 | 物理 | 化学 | 生物 | 天文 | 技术 | 管理 | 公告 |
| ---- | ------- | ---- | ------- | ----- | ---- | ----- | ------ |
| math | physics | chem | biology | astro | tech | admin | announ |
| 其他 | 语言 | 社科 | 科幻 | 辑录 |
| ------ | ---- | ------ | ------ | ----------- |
| others | lang | socsci | sci-fi | collections |`,
handler
};
async function handler(ctx) {
const { channel = "all" } = ctx.req.param();
const rootUrl = "https://chaoli.club";
const currentUrl = `${rootUrl}/index.php/conversations/${channel}`;
const $ = load(await rofetch(currentUrl));
const list = $(".title a").slice(0, 10).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));
return {
...item,
author: content(".info h3").eq(0).text(),
description: content(".postBody").eq(0).html(),
pubDate: parseDate(Number.parseInt(content(".info .time").attr("data-timestamp")) * 1e3)
};
})));
return {
title: $("title").text(),
link: currentUrl,
item: items
};
}
//#endregion
export { route };