UNPKG

rsshub

Version:
89 lines (87 loc) 2.79 kB
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; import { t as got_default } from "./got-BTowW50G.mjs"; import { i as viewThread, n as countReplies, t as renderContent } from "./content-C9CX5mHv.mjs"; import { Fragment, jsx, jsxs } from "hono/jsx/jsx-runtime"; import { renderToString } from "hono/jsx/dom/server"; import { raw } from "hono/html"; //#region lib/routes/lkong/thread.tsx const route = { path: "/thread/:id", categories: ["bbs"], example: "/lkong/thread/3100275", parameters: { id: "帖子 id, 可在帖子的URL里找到" }, radar: [{ source: ["lkong.com/thread/:id", "lkong.com/"] }], name: "帖子", maintainers: ["nczitzk", "ma6254"], handler }; async function handler(ctx) { const id = ctx.req.param("id"); const rootUrl = "https://www.lkong.com"; const apiUrl = "https://api.lkong.com/api"; const currentUrl = `${rootUrl}/thread/${id}`; const countResponse = await got_default({ method: "post", url: apiUrl, json: countReplies(id) }); if (countResponse.data.errors) throw new Error(countResponse.data.errors[0].message); const response = await got_default({ method: "post", url: apiUrl, json: viewThread(id, Math.ceil(countResponse.data.data.thread.replies / 20)) }); const items = response.data.data.posts.map((item) => ({ guid: item.pid, author: item.user.name, title: `#${item.lou} ${item.user.name}`, link: `${rootUrl}/thread/${id}?pid=${item.pid}`, pubDate: parseDate(item.dateline), description: (item.quote ? renderToString(/* @__PURE__ */ jsx(LkongQuote, { target: `${rootUrl}/thread/${id}?pid=${item.quote.pid}`, author: item.quote.author.name, content: renderContent(JSON.parse(item.quote.content)) })) : "") + renderContent(JSON.parse(item.content)) })); return { title: `${response.data.data.thread.title} - 龙空`, link: currentUrl, item: items }; } const quoteStyles = ` .quote { margin: 15px 0px 15px; width: 100%; border: 1px solid #eee; background-color: #f5f5f5; border-radius: 4px; padding: 8px 14px; cursor: pointer; } .quote-link { color: #1890ff; text-decoration: none; } `; const LkongQuote = ({ target, author, content }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", { class: "quote", children: [ /* @__PURE__ */ jsxs("a", { href: target, class: "quote-link", children: [/* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: "13.16", height: "12", viewBox: "0 0 13.16 12", class: "css-1f5j0lz", children: /* @__PURE__ */ jsx("path", { d: "M5.71,0,0,5l5.71,5V6.57S13.63,4,12,12c0,0,5.11-9.71-6.42-9L5.71,0Z" }) }), author] }), ":", raw(content) ] }), /* @__PURE__ */ jsx("style", { children: quoteStyles })] }); //#endregion export { route };