UNPKG

rsshub

Version:
83 lines (81 loc) 2.91 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 { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import path from "node:path"; import * as cheerio from "cheerio"; //#region lib/routes/yenpress/series.ts init_esm_shims(); const render = (data) => art(path.join(__dirname, "templates/series-6e2b9a1d.art"), data); const route = { path: "/series/:name", example: "/yenpress/series/alya-sometimes-hides-her-feelings-in-russian", parameters: { name: "Series name" }, name: "Series", maintainers: ["TonyRL"], handler, radar: [{ source: ["yenpress.com/series/:name"], target: "/series/:name" }] }; async function handler(ctx) { const { name: series } = ctx.req.param(); const baseUrl = "https://yenpress.com"; const link = `https://yenpress.com/series/${series}`; const response = await ofetch_default(link); const $ = cheerio.load(response); const list = $(".show-more-container .inline_block").toArray().map((item) => { const $item = $(item); return { title: $item.find("span").text().trim(), link: new URL($item.find("a").attr("href"), baseUrl).href }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const response$1 = await ofetch_default(item.link); const $$1 = cheerio.load(response$1); item.category = $$1(".detail-labels.mobile-only").eq(0).find("a").toArray().map((a) => $$1(a).text().trim()); $$1("svg, .social-share, .desktop-only, .detail-labels").remove(); const cover = $$1(".book-info").find(".book-cover-img").html(); const bookInfo = $$1(".buy-info .deliver").toArray().map((item$1, i) => ({ deliver: $$1(item$1).text().trim(), price: $$1(".book-price").eq(i).text().trim(), from: $$1(".services").eq(i).find(".service").toArray().map((service) => { const a = $$1(service).find("a"); return { name: a.text().trim(), link: a.attr("href") }; }), detail: $$1(".detail-info").eq(i).find("div span").toArray().map((span) => { const $span = $$1(span); return { key: $span.text().trim(), value: $span.next().text().trim() }; }) })); const info = $$1(".book-info"); info.find(".buy-info, .series-cover").remove(); item.description = render({ cover: cover + info.html(), bookInfo }); item.pubDate = timezone(parseDate(bookInfo[0].detail.find((d) => d.key === "Release Date").value), 0); return item; }))); return { title: $("head title").text().trim(), description: $(".social-share p").text().trim(), link, item: items }; } //#endregion export { route };