UNPKG

rsshub

Version:
67 lines (65 loc) 2.23 kB
import "./esm-shims-CzJ_djXG.mjs"; import "./config-C37vj7VH.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import "./helpers-DxBp0Pty.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { load } from "cheerio"; //#region lib/routes/douban/other/discussion.ts const route = { path: "/:id/discussion", categories: ["social-media"], example: "/douban/36328704/discussion", parameters: { id: "书本id;默认论坛文章使用\"按回应时间排序\",仅第一页文章" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["book.douban.com/:id/discussion"] }], name: "豆瓣读书论坛", maintainers: ["nightmare-mio"], handler }; async function handler(ctx) { const id = ctx.req.param("id"); const link = "https://book.douban.com/subject"; const { data: response } = await got_default(`${link}/${id}/discussion/`); const $ = load(response); const list = $("#posts-table>tbody>tr").toArray().slice(1).map((item) => { item = $(item); const a = item.find("a").first(); return { title: a.attr("title"), link: a.attr("href"), pubDate: parseDate(item.find(".time").text()), author: item.find("a").eq(1).text() }; }); const title = $("#content>h1").text(); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const { data: response$1 } = await got_default(item.link); const $$1 = load(response$1); const replyContent = $$1("#comments>.comment-item").toArray().map((item$1, index) => { const post = $$1(item$1); const content = post.find(".content>p").html(); const author = post.find(".author>a").text(); return `<p><div>#${index + 1}: <i>${author}</i></div><div>${content}</div></p>`; }).join(""); item.description = `${$$1("#link-report>div").eq(1).html()}<div>${replyContent}</div>`; return item; }))); return { title, link: `${link}/${id}/discussion`, item: items }; } //#endregion export { route };