UNPKG

rsshub

Version:
29 lines (27 loc) 1.46 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.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/jpxgmn/utils.ts init_esm_shims(); const indexUrl = "http://mei8.vip/"; const getOriginUrl = async () => await cache_default.tryGet("jpxgmn:originUrl", async () => { const $ = load((await got_default(indexUrl)).data); const entries = $("ul > li > span"); return "http://" + $(entries[Math.floor(Math.random() * entries.length)]).text(); }); const getImages = ($articleContent) => $articleContent("article > p img").toArray().map((img) => $articleContent(img).attr("src")); const getArticleDesc = async (articleUrl) => { const $content = load((await got_default(articleUrl)).data); let pageCnt = $content("div.pagination:first ul a").length - 1; if (pageCnt === -1) pageCnt = 1; const images = getImages($content); const otherImages = await Promise.all([...Array.from({ length: pageCnt - 1 }).keys()].map(async (pageIndex) => { return getImages(load((await got_default(articleUrl.replace(".html", `_${pageIndex + 1}.html`))).data)); })); return art(path.join(__dirname, "templates/description-7371506b.art"), { images: [...images, ...otherImages.flat()] }); }; //#endregion export { getOriginUrl as n, getArticleDesc as t };