UNPKG

rsshub

Version:
77 lines (75 loc) 2.56 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 { 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/routledge/book-series.ts init_esm_shims(); const route = { path: "/:bookName/book-series/:bookId", radar: [{ source: ["routledge.com/:bookName/book-series/:bookId"] }], name: "Unknown", maintainers: ["TonyRL"], handler }; async function handler(ctx) { const { bookName, bookId } = ctx.req.param(); const pageUrl = `https://www.routledge.com/${bookName}/book-series/${bookId}`; const { data: response } = await got_default(pageUrl, { headers: { accept: "text/html, */*; q=0.01" }, searchParams: { publishedFilter: "alltitles", pd: "published,forthcoming", pg: 1, pp: 12, so: "pub", view: "list" } }); const $ = load(response); const list = $(".row.book").toArray().map((item) => { item = $(item); const title = item.find("h3 a"); const description = item.find("p.description"); const meta = item.find("p.description").prev().text().split("\n"); return { title: title.text(), link: title.attr("href"), description: description.text(), pubDate: parseDate(meta.pop().trim(), "MMMM DD, YYYY"), author: meta.map((i) => i.trim()).filter(Boolean).join(", ") }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const { data } = await got_default(item.link); const $$1 = load(data); const { data: image } = await got_default("https://productimages.routledge.com", { searchParams: { isbn: $$1("meta[property=\"books:isbn\"]").attr("content"), size: "amazon", ext: "jpg" } }); const description = $$1(".sticky-div"); description.find("button.accordion-button").contents().unwrap(); description.find(".fa-shopping-cart").parent().parent().remove(); item.description = art(path.join(__dirname, "templates/description-c2244266.art"), { image, description: description.html() }); return item; }))); return { title: $("head title").text(), description: $("head meta[name=\"description\"]").attr("content"), link: pageUrl, item: items }; } //#endregion export { route };