UNPKG

rsshub

Version:
79 lines (77 loc) 2.7 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 "./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/patagonia/new-arrivals.ts init_esm_shims(); const host = "https://www.patagonia.com"; const categoryMap = { mens: ["mens-new", "mens-new-arrivals"], womens: ["womens-new", "womens-new-arrivals"], kids: ["kids-new-arrivals", "kids-baby-new-arrivals"], luggage: ["luggage-new-arrivals", "luggage-new-arrivals"] }; function extractSfrmUrl(url) { const urlObj = new URL(url); const sfrmValue = urlObj.searchParams.get("sfrm"); urlObj.search = new URLSearchParams({ sfrm: sfrmValue }).toString(); return urlObj.toString(); } const route = { path: "/new-arrivals/:category", categories: ["shopping"], example: "/patagonia/new-arrivals/mens", parameters: { category: "category, see below" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "New Arrivals", maintainers: [], handler, description: `| Men's | Women's | Kids' & Baby | Packs & Gear | | ----- | ------- | ------------ | ------------ | | mens | womens | kids | luggage |` }; async function handler(ctx) { const category = ctx.req.param("category"); const data = (await got_default({ method: "get", url: `${host}/on/demandware.store/Sites-patagonia-us-Site/en_US/Search-LazyGrid`, searchParams: { cgid: categoryMap[category][0], isLazyGrid: true } })).data; const $ = load(data); const list = $(".product").toArray().map((element) => { const data$1 = { title: $(element).find(".product-tile").data("tealium").product_name[0], link: host + "/" + $(element).find("[itemprop=\"url\"]").attr("href"), description: "", category: $(element).find("[itemprop=\"category\"]").attr("content") }; let imgUrl = new URL($(element).find("[itemprop=\"image\"]").attr("content")); imgUrl = extractSfrmUrl(imgUrl); data$1.description = $(element).find("[itemprop=\"price\"]").eq(0).text() + art(path.join(__dirname, "templates/product-description-5678e430.art"), { imgUrl }); return data$1; }); return { title: `Patagonia - New Arrivals - ${category.toUpperCase()}`, link: `${host}/shop/${categoryMap[category][1]}`, description: `Patagonia - New Arrivals - ${category.toUpperCase()}`, item: list }; } //#endregion export { route };