UNPKG

rsshub

Version:
79 lines (73 loc) 3.29 kB
import { t as parseDate } from "./parse-date-Cr0wQjV_.mjs"; import { t as cache_default } from "./cache-BkqOokyU.mjs"; import { t as got_default } from "./got-BTowW50G.mjs"; import { t as timezone } from "./timezone-BBvDwS_3.mjs"; import { t as InvalidParameterError } from "./invalid-parameter-CGxhjomn.mjs"; import { t as isValidHost } from "./valid-host-BH9Dd2Pf.mjs"; import { t as parseArticle } from "./utils-DHK_qm51.mjs"; import { load } from "cheerio"; //#region lib/routes/caixin/category.ts const route = { path: "/:column/:category", categories: ["traditional-media"], example: "/caixin/finance/regulation", parameters: { column: "栏目名", category: "栏目下的子分类名" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: true, supportScihub: false }, name: "新闻分类", maintainers: ["idealclover"], handler, description: `Column 列表: | 经济 | 金融 | 政经 | 环科 | 世界 | 观点网 | 文化 | 周刊 | | ------- | ------- | ----- | ------- | ------------- | ------- | ------- | ------ | | economy | finance | china | science | international | opinion | culture | weekly | 以金融板块为例的 category 列表:(其余 column 以类似方式寻找) | 监管 | 银行 | 证券基金 | 信托保险 | 投资 | 创新 | 市场 | | ---------- | ---- | -------- | ---------------- | ---------- | ---------- | ------ | | regulation | bank | stock | insurance\\_trust | investment | innovation | market | Category 列表: | 封面报道 | 开卷 | 社论 | 时事 | 编辑寄语 | 经济 | 金融 | 商业 | 环境与科技 | 民生 | 副刊 | | ---------- | ----- | --------- | ---------------- | ------------ | ------- | ------- | -------- | ----------------------- | ------- | ------ | | coverstory | first | editorial | current\\_affairs | editor\\_desk | economy | finance | business | environment\\_technology | cwcivil | column |` }; async function handler(ctx) { const category = ctx.req.param("category"); const column = ctx.req.param("column"); const url = `https://${column}.caixin.com/${category}`; if (!isValidHost(column)) throw new InvalidParameterError("Invalid column"); const $ = load((await got_default(url)).data); const title = $("head title").text(); const { data: { datas: data } } = await got_default("https://gateway.caixin.com/api/extapi/homeInterface.jsp", { searchParams: { subject: JSON.parse($("script").text().match(/var entity = (\{.*?\})/)[1]).id, type: 0, count: ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 25, picdim: "_266_177", start: 0 } }); const list = data.map((item) => ({ title: item.desc, description: item.summ, link: item.link.replace("http://", "https://"), pubDate: timezone(parseDate(item.time), 8), category: item.keyword.split(" "), audio: item.audioUrl, audio_image_url: item.pict.imgs[0].url })); return { title, link: url, description: "财新网 - 提供财经新闻及资讯服务", item: await Promise.all(list.map((item) => cache_default.tryGet(item.link, () => parseArticle(item)))) }; } //#endregion export { route };