UNPKG

rsshub

Version:
46 lines (45 loc) 1.41 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.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 response = await rofetch(baseUrl); const $ = load(response); 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 result = await rofetch(item.link, { headers: { Referer: baseUrl } }); const content = load(result); 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 };