UNPKG

rsshub

Version:
52 lines (51 loc) 1.85 kB
import { t as rofetch } from "./ofetch-U0CdpE2g.mjs"; import { t as parseDate } from "./parse-date-3kcy2Eau.mjs"; import { t as cache_default } from "./cache-C1Y-9qDV.mjs"; import { t as timezone } from "./timezone-UiMFOuvL.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 shopResponse = await rofetch(shopUrl); const $ = load(shopResponse); 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 detailResponse = await rofetch(item.link); const content = load(detailResponse); 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 };