UNPKG

rsshub

Version:
104 lines (103 loc) 3.78 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 renderDescription } from "./description-nDXjhA1h.mjs"; import { load } from "cheerio"; //#region lib/routes/logclub/report.ts const route = { path: "/lc_report/:id?", categories: ["new-media"], example: "/logclub/lc_report", parameters: { id: "报告 id,见下表,默认为罗戈研究出品" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [ { source: ["logclub.com/lc_report"], target: "/lc_report" }, { title: "报告 - 罗戈研究出品", source: ["logclub.com/lc_report"], target: "/lc_report/Report" }, { title: "报告 - 物流报告", source: ["logclub.com/lc_report"], target: "/lc_report/IndustryReport" }, { title: "报告 - 绿色双碳报告", source: ["logclub.com/lc_report"], target: "/lc_report/GreenDualCarbonReport" } ], name: "报告", maintainers: ["nczitzk"], handler, description: `| 罗戈研究出品 | 物流报告 | 绿色双碳报告 | | ------------ | -------------- | --------------------- | | Report | IndustryReport | GreenDualCarbonReport |` }; async function handler(ctx) { const { id = "Report" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number(ctx.req.query("limit")) : 11; const rootUrl = "https://www.logclub.com"; const currentUrl = new URL("lc_report", rootUrl).href; const apiUrl = new URL(`front/lc_report/load${id}List`, rootUrl).href; const { data: response } = await got_default.post(apiUrl, { json: { page: 1 } }); let items = response.list.slice(0, limit).map((item) => ({ title: item.title, link: new URL(`front/lc_report/get_report_info/${item.id}`, rootUrl).href, description: renderDescription({ image: { src: item.img_url?.split(/\?/, 1)[0] ?? void 0, alt: item.title } }), author: item.author, category: [item.channel_name], guid: `logclub-report-${item.id}`, pubDate: timezone(parseDate(item.release_time), 8) })); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const { data: detailResponse } = await got_default(item.link); const content = load(detailResponse); content("img").each((_, el) => { const $el = content(el); $el.replaceWith(renderDescription({ image: { src: $el.prop("src")?.split(/\?/, 1)[0] ?? void 0, alt: $el.prop("title") } })); }); item.title = content("h1").first().text(); item.description += renderDescription({ description: content("div.article-cont").html() ?? void 0 }); item.author = content("div.lc-infos a").toArray().map((a) => content(a).text()).join("/"); item.category = [.../* @__PURE__ */ new Set([...item.category ?? [], ...content("div.article-label-r a.label").toArray().map((c) => content(c).text())])].filter(Boolean); return item; }))); const { data: currentResponse } = await got_default(currentUrl); const $ = load(currentResponse); const title = $("div.this_nav").text().trim(); const icon = new URL($("link[rel=\"shortcut icon\"]").prop("href"), rootUrl).href; const subtitle = $("meta[name=\"keywords\"]").prop("content"); return { item: items, title: `${$("title").text()}${title}`, link: currentUrl, description: $("meta[name=\"description\"]").prop("content"), language: "zh", image: new URL($("div.logo_img img").prop("src"), rootUrl).href, icon, logo: icon, subtitle: subtitle.replaceAll(",", ""), author: subtitle.split(/,/, 1)[0] }; } //#endregion export { route };