UNPKG

rsshub

Version:
91 lines (82 loc) 3.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 "./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 { t as timezone } from "./timezone-D8cuwzTY.mjs"; import { i as processItems, n as convertToQueryString, o as rootUrl, r as getInfo, s as title, t as categories } from "./util-Csp1O1k0.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/mydrivers/index.ts init_esm_shims(); const route = { path: "/:category{.+}?", name: "分类", parameters: { category: "分类,见下表,默认为最新" }, example: "/mydrivers/bcid/801", maintainers: ["kt286", "nczitzk"], handler, radar: [{ source: ["m.mydrivers.com/"], target: "/zhibo" }], description: ` #### 板块 | 电脑 | 手机 | 汽车 | 业界 | 游戏 | | -------- | -------- | -------- | -------- | -------- | | bcid/801 | bcid/802 | bcid/807 | bcid/803 | bcid/806 | #### 话题 | 科学 | 排行 | 评测 | 一图 | | -------- | -------- | -------- | -------- | | tid/1000 | tid/1001 | tid/1002 | tid/1003 | #### 品牌 | 安卓 | 阿里 | 微软 | 百度 | PS5 | Xbox | 华为 | | -------- | -------- | ------- | ------- | --------- | -------- | -------- | | icid/121 | icid/270 | icid/90 | icid/67 | icid/6950 | icid/194 | icid/136 | | 小米 | VIVO | 三星 | 魅族 | 一加 | 比亚迪 | 小鹏 | | --------- | -------- | -------- | -------- | -------- | -------- | --------- | | icid/9355 | icid/288 | icid/154 | icid/140 | icid/385 | icid/770 | icid/7259 | | 蔚来 | 理想 | 奔驰 | 宝马 | 大众 | | --------- | ---------- | -------- | -------- | -------- | | icid/7318 | icid/12947 | icid/429 | icid/461 | icid/481 | ` }; async function handler(ctx) { let { category = "new" } = ctx.req.param(); let newTitle = ""; if (!/^(\w+\/\w+)$/.test(category)) { newTitle = `${title} - ${Object.hasOwn(categories, category) ? categories[category] : categories[Object.keys(categories)[0]]}`; category = `ac/${category}`; } const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 20; const queryString = convertToQueryString(category); const currentUrl = new URL(`newsclass.aspx${queryString}`, rootUrl).href; const apiUrl = new URL(`m/newslist.ashx${queryString}`, rootUrl).href; const { data: response } = await got_default(apiUrl); const $ = load(response); let items = $("li[data-id]").slice(0, limit).toArray().map((item) => { item = $(item); return { title: item.find("div.news_title").text(), link: new URL(item.find("div.news_title span.newst a").prop("href"), rootUrl).href, description: art(path.join(__dirname, "templates/description-8ef00cc6.art"), { image: item.find("a.newsimg img").prop("src") }), author: item.find("p.tname").text(), guid: item.prop("data-id"), pubDate: timezone(parseDate(item.find("p.ttime").text()), 8), comments: item.find("a.tpinglun").text() ? Number.parseInt(item.find("a.tpinglun").text(), 10) : 0 }; }); items = await processItems(items); return { ...await getInfo(currentUrl), ...newTitle ? { title: newTitle } : {}, item: items }; } //#endregion export { route };