UNPKG

rsshub

Version:
84 lines (82 loc) 2.89 kB
import "./esm-shims-CzJ_djXG.mjs"; import { t as config } from "./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 got_default } from "./got-KxxWdaxq.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { t as config_not_found_default } from "./config-not-found-Dyp3RlZZ.mjs"; import { t as getHeaders } from "./utils-BXkxCuHO.mjs"; import { load } from "cheerio"; //#region lib/routes/smzdm/haowen-fenlei.ts const route = { path: "/haowen/fenlei/:name/:sort?", categories: ["shopping"], example: "/smzdm/haowen/fenlei/shenghuodianqi", parameters: { name: "分类名,可在 URL 中查看", sort: "排序方式,默认为最新" }, features: { requireConfig: [{ name: "SMZDM_COOKIE", description: "什么值得买登录后的 Cookie 值" }], requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["post.smzdm.com/fenlei/:name"], target: "/haowen/fenlei/:name" }], name: "好文分类", maintainers: ["LogicJake"], handler, description: `| 最新 | 周排行 | 月排行 | | ---- | ------ | ------ | | 0 | 7 | 30 |` }; async function handler(ctx) { if (!config.smzdm.cookie) throw new config_not_found_default("什么值得买排行榜 is disabled due to the lack of SMZDM_COOKIE"); const name = ctx.req.param("name"); const sort = ctx.req.param("sort") || "0"; const link = sort === "0" ? `https://post.smzdm.com/fenlei/${name}/` : `https://post.smzdm.com/fenlei/${name}/hot_${sort}/`; const $ = load((await got_default.get(link, { headers: getHeaders() })).data); const title = $("div.crumbs.nav-crumbs").text().split(">").pop(); const list = $("div.list.post-list").toArray().map((item) => { item = $(item); return { title: item.find("h2.item-name a").text(), link: item.find("h2.item-name a").attr("href"), description: item.find(".item-info").html(), author: item.find(".nickname").text(), pubDate: timezone(parseDate(item.find("span.time").text(), [ "HH:mm", "MM-DD HH:mm", "YYYY-MM-DD HH:mm" ]), 8) }; }); const out = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { try { const $$1 = load((await got_default(item.link, { headers: getHeaders() })).data); item.description = $$1("article").html(); item.pubDate = timezone(parseDate($$1("meta[property=\"og:release_date\"]").attr("content")), 8); item.author = $$1("meta[property=\"og:author\"]").attr("content"); } catch {} return item; }))); return { title: `${title}- 什么值得买好文分类`, link, item: out }; } //#endregion export { route };