UNPKG

rsshub

Version:
126 lines (124 loc) 4.52 kB
import { n as init_esm_shims, t as __dirname } from "./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 art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { n as rootUrl, t as getSearchParams } from "./utils-BwpBAMuc.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/cls/subject.ts init_esm_shims(); const handler = async (ctx) => { const { id = "1103" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 20; const currentUrl = new URL(`subject/${id}`, rootUrl).href; const apiUrl = new URL(`api/subject/${id}/article`, rootUrl).href; const { data: response } = await got_default(apiUrl, { searchParams: getSearchParams({ Subject_Id: id }) }); let items = response.data.slice(0, limit).map((item) => { const title = item.article_title; const description = art(path.join(__dirname, "templates/description-881baa33.art"), { intro: item.article_brief }); const guid = `cls-${item.article_id}`; const image$1 = item.article_img; return { title, description, pubDate: parseDate(item.article_time, "X"), link: new URL(`detail/${item.article_id}`, rootUrl).href, category: item.subjects.map((s) => s.subject_name), author: item.article_author, guid, id: guid, content: { html: description, text: item.article_brief }, image: image$1, banner: image$1 }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const { data: detailResponse } = await got_default(item.link); const $$ = load(detailResponse); const data$1 = JSON.parse($$("script#__NEXT_DATA__").text())?.props?.initialState?.detail?.articleDetail ?? void 0; if (!data$1) return item; const title = data$1.title; const description = art(path.join(__dirname, "templates/description-881baa33.art"), { images: data$1.images.map((i) => ({ src: i, alt: title })), intro: data$1.brief, description: data$1.content }); const guid = `cls-${data$1.id}`; const image$1 = data$1.images?.[0] ?? void 0; item.title = title; item.description = description; item.pubDate = parseDate(data$1.ctime, "X"); item.category = [...new Set(data$1.subject?.flatMap((s) => [s.name, ...s.subjectCategory?.flatMap((c) => [c.columnName || [], c.name || []]) ?? []]))].filter(Boolean); item.author = data$1.author?.name ?? item.author; item.guid = guid; item.id = guid; item.content = { html: description, text: data$1.content }; item.image = image$1; item.banner = image$1; item.enclosure_url = data$1.audioUrl; item.enclosure_type = item.enclosure_url ? `audio/${item.enclosure_url.split(/\./).pop()}` : void 0; item.enclosure_title = title; return item; }))); const { data: currentResponse } = await got_default(currentUrl); const $ = load(currentResponse); const data = JSON.parse($("script#__NEXT_DATA__").text())?.props?.initialProps?.pageProps?.subjectDetail ?? void 0; const author = "财联社"; const image = data?.img ?? void 0; return { title: `${author} - ${data?.name ?? $("title").text()}`, description: data?.description ?? void 0, link: currentUrl, item: items, allowEmpty: true, image, author }; }; const route = { path: "/subject/:id?", name: "话题", url: "www.cls.cn", maintainers: ["nczitzk"], handler, example: "/cls/subject/1103", parameters: { category: "分类,默认为 1103,即A股盘面直播,可在对应话题页 URL 中找到" }, description: `::: tip 若订阅 [有声早报](https://www.cls.cn/subject/1151),网址为 \`https://www.cls.cn/subject/1151\`。截取 \`https://www.cls.cn/subject/\` 到末尾的部分 \`1151\` 作为参数填入,此时路由为 [\`/cls/subject/1151\`](https://rsshub.app/cls/subject/1151)。 ::: `, categories: ["finance"], features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportRadar: true, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["www.cls.cn/subject/:id"], target: (params) => { const id = params.id; return `/subject${id ? `/${id}` : ""}`; } }] }; //#endregion export { handler, route };