rsshub
Version:
Make RSS Great Again!
58 lines (56 loc) • 1.8 kB
JavaScript
import "./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 cache_default } from "./cache-Bo__VnGm.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 };