UNPKG

rsshub

Version:
58 lines (56 loc) 1.8 kB
import "./dist-Bog6z_OM.mjs"; import "./config-MQ-7ebJ_.mjs"; import "./logger-C4avouvV.mjs"; import { t as ofetch_default } from "./ofetch-DKl_Ma9g.mjs"; import "./is-worker-DESPicPc.mjs"; import { t as cache_default } from "./cache-SV6W5EPy.mjs"; import { load } from "cheerio"; //#region lib/routes/luogu/user-blog.ts const route = { path: "/user/blog/:name", categories: ["programming"], example: "/luogu/user/blog/ftiasch", parameters: { name: "博客名称" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["luogu.com/blog/:name"] }, { source: ["luogu.com.cn/blog/:name"] }], name: "用户博客", maintainers: ["ftiasch"], handler }; async function handler(ctx) { const blogBaseUrl = `https://www.luogu.com.cn/blog/${ctx.req.param("name")}/`; const { uid: blogUid, title: blogTitle } = await cache_default.tryGet(blogBaseUrl, async () => { const $ = load(await ofetch_default(blogBaseUrl)); return { uid: $("meta[name='blog-uid']").attr("content"), title: `${$("meta[name='blog-name']").attr("content")} - 洛谷博客` }; }); const posts = (await ofetch_default(`https://www.luogu.com.cn/api/blog/lists?uid=${blogUid}`)).data.result.map((r) => ({ title: r.title, link: `${blogBaseUrl}${r.identifier}`, pubDate: /* @__PURE__ */ new Date(r.postTime * 1e3) })); return { title: blogTitle, link: blogBaseUrl, item: await Promise.all(posts.map((post) => cache_default.tryGet(post.link, async () => { const $ = load(await ofetch_default(post.link)); return { title: post.title, link: post.link, pubDate: post.pubDate, description: $("#article-content").html() }; }))) }; } //#endregion export { route };