UNPKG

rsshub

Version:
161 lines (158 loc) 6.22 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 { t as cache_default } from "./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 path from "node:path"; import { load } from "cheerio"; //#region lib/routes/a9vg/index.ts init_esm_shims(); const handler = async (ctx) => { const { category = "news/All" } = ctx.req.param(); const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 15; const rootUrl = "http://www.a9vg.com"; const currentUrl = new URL(`list/${category}`, rootUrl).href; const { data: response } = await got_default(currentUrl); const $ = load(response); const language = $("html").prop("lang"); let items = $("a.a9-rich-card-list_item").slice(0, limit).toArray().map((item) => { item = $(item); const image$1 = item.find("img.a9-rich-card-list_image"); const title$1 = item.find("div.a9-rich-card-list_label").text(); return { title: title$1, link: new URL(item.prop("href"), rootUrl).href, description: art(path.join(__dirname, "templates/description-16be3a2a.art"), { images: image$1 ? [{ src: image$1.prop("src"), alt: title$1 }] : void 0 }), pubDate: timezone(parseDate(item.find("div.a9-rich-card-list_infos").text()), 8), language }; }); items = await Promise.all(items.map((item) => cache_default.tryGet(item.link, async () => { const { data: detailResponse } = await got_default(item.link); const $$ = load(detailResponse); $$("ignore_js_op img, p img").each((_, el) => { el = $$(el); el.parent().replaceWith(art(path.join(__dirname, "templates/description-16be3a2a.art"), { images: el.prop("file") ? [{ src: el.prop("file"), alt: el.next().find("div.xs0 p").first().text() }] : void 0 })); }); item.title = $$("h1.ts, div.c-article-main_content-title").first().text(); item.description = art(path.join(__dirname, "templates/description-16be3a2a.art"), { description: $$("td.t_f, div.c-article-main_contentraw").first().html() }); item.author = $$("b a.blue").first().text() || $$($$("span.c-article-main_content-intro-item").toArray().findLast((i) => $$(i).text().startsWith("作者"))).text().split(/:/).pop(); item.pubDate = timezone(parseDate($$("div.authi em").first().text().trim().match(/发表于 (\d+-\d+-\d+ \d+:\d+)/)?.[1] ?? $$("span.c-article-main_content-intro-item").first().text(), ["YYYY-M-D HH:mm", "YYYY-MM-DD HH:mm"]), 8); item.language = language; return item; }))); const title = $("title").text(); const image = new URL("images/logo.1cee7c0f.svg", rootUrl).href; return { title, description: $("meta[name=\"description\"]").prop("content"), link: currentUrl, item: items, allowEmpty: true, image, author: title.split(/-/).pop(), language }; }; const route = { path: "/:category{.+}?", name: "新闻", url: "a9vg.com", maintainers: ["monnerHenster", "nczitzk"], handler, example: "/a9vg/news", parameters: { category: "分类,默认为 ,可在对应分类页 URL 中找到, Category, by default" }, description: `::: tip 若订阅 [PS4](http://www.a9vg.com/list/news/PS4),网址为 \`http://www.a9vg.com/list/news/PS4\`。截取 \`http://www.a9vg.com/list\` 到末尾的部分 \`news/PS4\` 作为参数填入,此时路由为 [\`/a9vg/news/PS4\`](https://rsshub.app/a9vg/news/PS4)。 ::: | 分类 | ID | | -------------------------------------------------- | ------------------------------------------------------ | | [All](https://www.a9vg.com/list/news/All) | [news/All](https://rsshub.app/a9vg/news/All) | | [PS4](https://www.a9vg.com/list/news/PS4) | [news/PS4](https://rsshub.app/a9vg/news/PS4) | | [PS5](https://www.a9vg.com/list/news/PS5) | [news/PS5](https://rsshub.app/a9vg/news/PS5) | | [Switch](https://www.a9vg.com/list/news/Switch) | [news/Switch](https://rsshub.app/a9vg/news/Switch) | | [Xbox One](https://www.a9vg.com/list/news/XboxOne) | [news/XboxOne](https://rsshub.app/a9vg/news/XboxOne) | | [XSX](https://www.a9vg.com/list/news/XSX) | [news/XSX](https://rsshub.app/a9vg/news/XSX) | | [PC](https://www.a9vg.com/list/news/PC) | [news/PC](https://rsshub.app/a9vg/news/PC) | | [业界](https://www.a9vg.com/list/news/Industry) | [news/Industry](https://rsshub.app/a9vg/news/Industry) | | [厂商](https://www.a9vg.com/list/news/Factory) | [news/Factory](https://rsshub.app/a9vg/news/Factory) | `, categories: ["game"], features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportRadar: true, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [ { source: ["www.a9vg.com/list/:category"], target: (params) => { const category = params.category; return category ? `/${category}` : ""; } }, { title: "All", source: ["www.a9vg.com/list/news/All"], target: "/news/All" }, { title: "PS4", source: ["www.a9vg.com/list/news/PS4"], target: "/news/PS4" }, { title: "PS5", source: ["www.a9vg.com/list/news/PS5"], target: "/news/PS5" }, { title: "Switch", source: ["www.a9vg.com/list/news/Switch"], target: "/news/Switch" }, { title: "Xbox One", source: ["www.a9vg.com/list/news/XboxOne"], target: "/news/XboxOne" }, { title: "XSX", source: ["www.a9vg.com/list/news/XSX"], target: "/news/XSX" }, { title: "PC", source: ["www.a9vg.com/list/news/PC"], target: "/news/PC" }, { title: "业界", source: ["www.a9vg.com/list/news/Industry"], target: "/news/Industry" }, { title: "厂商", source: ["www.a9vg.com/list/news/Factory"], target: "/news/Factory" } ] }; //#endregion export { handler, route };