UNPKG

rsshub

Version:
105 lines (103 loc) 3.29 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 "./helpers-DxBp0Pty.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import path from "node:path"; import { load } from "cheerio"; import markdownit from "markdown-it"; //#region lib/routes/farmatters/index.ts init_esm_shims(); const md = markdownit({ html: true }); const ids = { 1: 0, 2: 2, 3: 1 }; const route = { path: [ "/exclusive/:locale?", "/news/:locale?", "/:locale?", "/:type/:id/:locale?" ], categories: ["new-media"], example: "/farmatters/exclusive", parameters: { locale: "Locale, `zh-CN` or `en-US`, `zh-CN` by default" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["farmatters.com/exclusive"], target: "/exclusive" }], name: "Exclusive", maintainers: ["nczitzk"], handler, url: "farmatters.com/news" }; async function handler(ctx) { const { type, id, locale = "zh-CN" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 50; const searchParams = { locale, page: 0, pagesize: limit }; if (type === "wiki" && id) searchParams.subCatalogId = id; else if (type && id) searchParams[type] = id; const rootUrl = "https://farmatters.com"; const apiUrl = new URL("api/v1/doc/list", rootUrl).href; const currentUrl = new URL(`${locale === "zh-CN" ? "" : "en/"}${type ? type === "wiki" ? "wiki" : `tag/${id}` : "news"}`, rootUrl).href; const { data: response } = await got_default(apiUrl, { searchParams, https: { rejectUnauthorized: false } }); const items = response.data.list.slice(0, limit).map((item) => ({ title: item.title, link: new URL(`doc/${item.id}`, rootUrl).href, description: art(path.join(__dirname, "templates/description-dcf20f08.art"), { image: item.headImageUrl ? { src: item.headImageUrl, alt: item.title } : void 0, description: md.render(item.content ?? item.summary) }), author: item.author, category: [ item.catalogName, item.subCatalogName ?? void 0, ...item.tags?.map((t) => t.tagName) ?? [] ].filter(Boolean), guid: `farmatters-${item.id}`, pubDate: timezone(parseDate(item.createdAt), 8) })); const { data: currentResponse } = await got_default(currentUrl, { https: { rejectUnauthorized: false } }); const $ = load(currentResponse); const subtitle = `${$("h4").first().text()}${type === "wiki" ? ` - ${$("div.css-6f6728 div.MuiBox-root").eq(ids[id]).text()}` : ""}`; const icon = new URL("favicon.ico", rootUrl).href; return { item: items, title: `${$("title").text().split(/-/)[0].trim()} - ${subtitle}`, link: currentUrl, description: $("meta[name=\"description\"]").prop("content"), language: $("html").prop("lang"), image: new URL($("img").first().prop("src"), rootUrl).href, icon, logo: icon, subtitle, allowEmpty: true }; } //#endregion export { route };