rsshub
Version:
Make RSS Great Again!
62 lines (60 loc) • 1.96 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 parseDate } from "./parse-date-BrP7mxXf.mjs";
import { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import "./got-KxxWdaxq.mjs";
import { t as getUserInfoFromUID } from "./utils-DpF8aM9J.mjs";
import * as cheerio from "cheerio";
//#region lib/routes/luogu/user-article.ts
const route = {
path: "/user/article/:uid",
categories: ["programming"],
example: "/luogu/user/article/1",
parameters: { name: "用户 UID" },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["luogu.com/user/:uid"] }, { source: ["luogu.com.cn/user/:uid"] }],
name: "用户文章",
maintainers: ["TonyRL"],
handler
};
const baseUrl = "https://www.luogu.com";
async function handler(ctx) {
const { uid } = ctx.req.param();
const userInfo = await getUserInfoFromUID(uid);
const posts = (await ofetch_default(`${baseUrl}/api/article/find`, { query: {
user: uid,
page: 1,
ascending: false
} })).articles.result.map((item$1) => ({
title: item$1.title,
link: `${baseUrl}/article/${item$1.lid}`,
author: item$1.author.name,
pubDate: parseDate(item$1.time, "X"),
description: item$1.content
}));
const item = await Promise.all(posts.map((item$1) => cache_default.tryGet(item$1.link, async () => {
const response = await ofetch_default(item$1.link);
item$1.description = cheerio.load(response)("div#rendered-preview").html();
return item$1;
})));
return {
title: `${userInfo.name} 的个人中心 - 洛谷 | 计算机科学教育新生态`,
description: userInfo.description,
link: `${baseUrl}/user/${uid}#article`,
image: userInfo.avatar,
item
};
}
//#endregion
export { route };