UNPKG

rsshub

Version:
50 lines (49 loc) 1.77 kB
import { t as rofetch } from "./ofetch-W1aeTHCo.mjs"; import { t as parseDate } from "./parse-date-CjhZE69i.mjs"; import { t as cache_default } from "./cache-CiDoUSLo.mjs"; import { t as timezone } from "./timezone-DE--ze1V.mjs"; import { load } from "cheerio"; //#region lib/routes/kongfz/shop.ts const route = { path: "/shop/:id/:cat?", categories: ["reading"], example: "/kongfz/shop/10067/1", parameters: { id: "店铺 id, 可在对应店铺页 URL 中找到", cat: "分类 id,可在对应分类页 URL 中找到,默认为店铺最新上架" }, name: "店铺上架", maintainers: ["nczitzk"], handler }; async function handler(ctx) { const { id, cat } = ctx.req.param(); const shopUrl = `http://shop.kongfz.com/${id}${cat ? `/cat_${cat}` : ""}`; const $ = load(await rofetch(shopUrl)); const list = $(cat ? "div.list-content div.item-row" : "div.newest_content span.rareBook_content_list").slice(0, 15).toArray().map((item) => { const $item = $(item); const a = cat ? $item.find("a").eq(0) : $item.find("div.rareBook_content_title a"); return { title: $item.text(), link: a.attr("href") }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const content = load(await rofetch(item.link)); content("#eventreport").remove(); content("div.buy-group").remove(); content("div.weixin-popup-bg").remove(); return { ...item, description: content("div.major-function").html() + `<img src="${content("ul.lg-list li img").attr("src")}">`, pubDate: timezone(parseDate(content("span.up-book-date-time").text()), 8) }; }))); return { title: `孔夫子旧书网 - ${$("title").text().split("_").at(-2)}`, link: shopUrl, item: items }; } //#endregion export { route };