UNPKG

rsshub

Version:
59 lines (57 loc) 2.05 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 { r as getSubPath } from "./common-utils-vrWQFAEk.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"; //#region lib/routes/ifeng/news.ts init_esm_shims(); const route = { path: "/news/*", name: "Unknown", maintainers: [], handler }; async function handler(ctx) { const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 20; const currentUrl = `https://news.ifeng.com${getSubPath(ctx).replace(/^\/news/, "")}`; const response = await got_default({ method: "get", url: currentUrl }); const $ = load(response.data); let items = JSON.parse(response.data.match(/"newsstream":(\[.*?]),"cooperation"/)[1]).slice(0, limit).map((item) => ({ title: item.title, link: item.url, pubDate: timezone(parseDate(item.newsTime), 8), description: item.thumbnails.image.pop() })); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const detailResponse = await got_default({ method: "get", url: item.link }); item.author = detailResponse.data.match(/"editorName":"(.*?)",/)[1]; item.category = detailResponse.data.match(/},"keywords":"(.*?)",/)[1].split(","); item.description = art(path.join(__dirname, "templates/description-d7e9cacc.art"), { image: item.description, description: JSON.parse(detailResponse.data.match(/"contentList":(\[.*?]),/)[1]).map((content) => content.data) }); return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; } //#endregion export { route };