rsshub
Version:
Make RSS Great Again!
44 lines (43 loc) • 1.36 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/wenxuecity/hot.ts
const route = {
path: "/hot/:cid",
categories: ["bbs"],
example: "/wenxuecity/hot/9",
parameters: { cid: "版面 ID, 可在 URL 中找到" },
name: "最热主题",
maintainers: ["changlan"],
handler
};
async function handler(ctx) {
const { cid } = ctx.req.param();
const baseUrl = `https://bbs.wenxuecity.com/?cid=${cid}/`;
const $ = load(await rofetch(baseUrl));
const list = $("div.item").toArray().slice(0, 10).map((item) => {
const $item = $(item);
return {
title: $item.find("div.title > a").text(),
link: new URL($item.find("div.title > a").attr("href"), "https://bbs.wenxuecity.com/").href,
author: $item.find("span.user > a").text()
};
});
const out = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => {
const content = load(await rofetch(item.link, { headers: { Referer: baseUrl } }));
return {
...item,
description: content("div#content").html(),
pubDate: parseDate(content("span.date").text())
};
})));
return {
allowEmpty: true,
title: $("title").text(),
link: baseUrl,
item: out
};
}
//#endregion
export { route };