UNPKG

rsshub

Version:
73 lines (71 loc) 2.58 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 path from "node:path"; //#region lib/routes/vcb-s/category.ts init_esm_shims(); const rootUrl = "https://vcb-s.com"; const cateAPIUrl = `${rootUrl}/wp-json/wp/v2/categories`; const postsAPIUrl = `${rootUrl}/wp-json/wp/v2/posts`; const route = { path: "/category/:cate", categories: ["anime"], example: "/vcb-s/category/works", parameters: { cate: "分类" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["vcb-s.com/archives/category/:cate"] }], name: "分类文章", maintainers: ["cxfksword"], handler, url: "vcb-s.com/", description: `| 作品项目 | 科普系列 | 计划与日志 | | -------- | -------- | ---------- | | works | kb | planlog |` }; async function handler(ctx) { const cate = ctx.req.param("cate"); const limit = ctx.req.query("limit") ?? 7; const cateUrl = `${cateAPIUrl}?slug=${cate}`; const category = await cache_default.tryGet(cateUrl, async () => { const res = await got_default.get(cateUrl); if (typeof res.data === "string") res.data = JSON.parse(res.body.trim()); return res.data[0]; }); const url = `${postsAPIUrl}?categories=${category.id}&page=1&per_page=${limit}&_embed`; const response = await got_default.get(url); if (typeof response.data === "string") response.data = JSON.parse(response.body.trim()); const items = response.data.map((item) => { const description = art(path.join(__dirname, "templates/post-a0d5f24f.art"), { post: item.content.rendered.replaceAll(/<pre class="js-medie-info-detail.*?>(.*?)<\/pre>/gs, "<pre><code>$1</code></pre>").replaceAll(/<div.+?dw-box-download.+?>(.*?)<\/div>/gs, "<pre>$1</pre>"), medias: item._embedded["wp:featuredmedia"] }); return { title: item.title.rendered, link: item.link, description, pubDate: parseDate(item.date_gmt), author: item._embedded.author[0].name }; }); return { title: `${category.name} | VCB-Studio`, link: `${rootUrl}/archives/category/${category.slug}`, item: items }; } //#endregion export { route };