rsshub
Version:
Make RSS Great Again!
55 lines (54 loc) • 1.59 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/bbs.ts
const route = {
path: "/bbs/:cat/:elite?",
categories: ["bbs"],
example: "/wenxuecity/bbs/tzlc",
parameters: {
cat: "版面名, 可在 URL 中找到",
elite: "是否精华区, 1 为精华区"
},
radar: [{
source: ["bbs.wenxuecity.com/:cat"],
target: "/bbs/:cat"
}, {
title: "最新主题 - 精华区",
source: ["bbs.wenxuecity.com/:cat"],
target: "/bbs/:cat/1"
}],
name: "最新主题",
maintainers: ["changlan"],
handler
};
async function handler(ctx) {
const { cat, elite = 0 } = ctx.req.param();
const baseUrl = `https://bbs.wenxuecity.com/${cat}/?elite=${elite}`;
const $ = load(await rofetch(baseUrl));
const list = $("div.odd,div.even").toArray().slice(0, 10).map((item) => {
const $item = $(item);
return {
title: $item.find("a.post").text(),
link: new URL($item.find("a.post").attr("href"), baseUrl).href,
author: $item.find("span.b > a.b").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 };