UNPKG

rsshub

Version:
67 lines (65 loc) 2.72 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 path from "node:path"; import { load } from "cheerio"; //#region lib/routes/thenewslens/index.ts init_esm_shims(); const route = { path: "*", name: "Unknown", maintainers: [], handler }; async function handler(ctx) { const currentUrl = `https://www.thenewslens.com${getSubPath(ctx) === "/" ? "/latest-article" : getSubPath(ctx)}`; const $ = load((await got_default({ method: "get", url: currentUrl })).data); $("h1.title").remove(); let items = $(".regular-article-list, #list-container, .list-container").find(".article-title, .title").find("a").slice(0, ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit")) : 25).toArray().map((item) => { item = $(item); const link = item.attr("href"); return { title: item.text(), link: /\/article\//.test(link) ? `${link}/fullpage` : link }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const content = load((await got_default({ method: "get", url: item.link })).data); content("#salon_comment_widget-anchor").remove(); content("ad2-recommender, footer, noscript").remove(); content("a[data-sk=\"tooltip_parent\"]").parent().remove(); content(".ad-section, .recommender-title, .navigation-content").remove(); content(".article-img-container").each(function() { content(this).replaceWith(art(path.join(__dirname, "templates/description-33e81d41.art"), { image: content(this).find("img")?.attr("data-srcset").split("?")[0] ?? void 0 })); }); item.author = content("meta[property=\"article:author\"]").attr("content"); item.pubDate = parseDate(content("meta[property=\"article:published_time\"]").attr("content")); item.category = content("meta[property=\"article:tag\"]").toArray().map((t) => content(t).attr("content")); item.description = art(path.join(__dirname, "templates/description-33e81d41.art"), { image: content("meta[property=\"og:image\"]")?.attr("content").split("?")[0] ?? void 0, description: content(".article-main-box, article[itemprop=\"articleBody\"]").html() }); return item; }))); return { title: $("title").text(), link: currentUrl, item: items }; } //#endregion export { route };