UNPKG

rsshub

Version:
87 lines (84 loc) 3.05 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 { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as cache_default } from "./cache-Bo__VnGm.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import path from "node:path"; import { load } from "cheerio"; //#region lib/routes/mcmod/index.ts init_esm_shims(); const render = (mod) => art(path.join(__dirname, "templates/mod-810bfe96.art"), { mod }); const route = { path: "/:type", categories: ["game"], example: "/mcmod/new", parameters: { type: "查询类型,详见下表" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, name: "最新MOD", maintainers: ["hualiong"], description: `\`:type\` 类型可选如下 | 随机显示MOD | 最新收录MOD | 最近编辑MOD | | ------ | --- | ---- | | random | new | edit |`, handler: async (ctx) => { const type = ctx.req.param("type"); const $get = ofetch_default.create({ baseURL: "https://www.mcmod.cn" }); const $ = load(await $get("/")); const typeName = $(`div.left > ul > li[i='${type}']`).attr("title"); const list = $(`#indexNew_${type} > .block`).toArray().map((item) => { const each = $(item); const time = each.find("div .time"); return { title: each.find("div > .name > a").text(), image: each.find("img").attr("src")?.split("@")[0], link: each.children("a").attr("href"), pubDate: time.attr("title") && timezone(parseDate(time.attr("title").slice(6), "YYYY-MM-DD HH:mm:ss"), 8) }; }); const items = await Promise.all(list.map((item) => cache_default.tryGet(item.link, async () => { const $$1 = load(await $get(item.link)); item.author = $$1(".author li").toArray().map((item$1) => { const each = $$1(item$1); const name = each.find(".name a"); return { name: name.text(), url: "https://www.mcmod.cn" + name.attr("href"), avatar: each.find(".avatar img").attr("src")?.split("?")[0] }; }); const html = $$1(".common-text[data-id=\"1\"]").html(); const support = $$1(".mcver > ul > ul").toArray().map((e) => { const ul = $$1(e); return { label: ul.children("li:first-child").text(), versions: ul.children("li:not(:first-child)").toArray().map((e$1) => $$1(e$1).text()).join(",") }; }); item.description = render({ pic: "https:" + item.image, label: $$1(".class-info li.col-lg-4").toArray().map((e) => $$1(e).text()), support }) + html.replaceAll(/\ssrc=".+?"/g, "").replaceAll("data-src", "src"); return item; }))); return { title: `${typeName} - MC百科`, description: $("meta[name=\"description\"]").attr("content"), link: "https://www.mcmod.cn", item: items }; } }; //#endregion export { route };