rsshub
Version:
Make RSS Great Again!
57 lines (55 loc) • 1.99 kB
JavaScript
import "./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 "./helpers-DxBp0Pty.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
//#region lib/routes/loongarch/post.ts
const route = {
path: "/post/:type?",
categories: ["bbs"],
example: "/loongarch/post/newest",
parameters: { type: "top 或 newest" },
radar: [{ source: ["bbs.loongarch.org"] }],
name: "最热 / 最新帖子",
maintainers: ["ladeng07", "3401797899"],
handler,
url: "bbs.loongarch.org/"
};
async function handler(ctx) {
const type = ctx.req.param("type");
const link = "https://bbs.loongarch.org/api/discussions";
let title = "最新帖子";
let sortValue = "-createdAt";
if (type === "top") {
title = "最热帖子";
sortValue = "-commentCount";
}
const { data: response } = await got_default("https://bbs.loongarch.org/api/discussions", { searchParams: {
include: "user,tags,tags.parent,firstPost",
sort: sortValue,
"page[offset]": 0
} });
const users = response.included.filter((i) => i.type === "users");
const tags = response.included.filter((i) => i.type === "tags");
const posts = response.included.filter((i) => i.type === "posts");
const out = response.data.map(({ attributes, relationships }) => ({
title: attributes.title,
link: `https://bbs.loongarch.org/d/${attributes.slug}`,
author: users.find((i) => i.id === relationships.user.data.id).attributes.displayName,
description: posts.find((i) => i.id === relationships.firstPost.data.id).attributes.contentHtml,
pubDate: parseDate(attributes.createdAt),
updated: parseDate(attributes.lastPostedAt),
category: relationships.tags.data.map((tag) => tags.find((i) => i.id === tag.id).attributes.name)
}));
return {
title: `LA UOSC-${title}`,
link,
description: `LA UOSC-${title}`,
item: out
};
}
//#endregion
export { route };