Files
endorphin-tabularium-docs/apps/docs/src/lib/collections.ts
T
codex-bot 422d6622a2
Verify and deploy Tabularium / verify-and-deploy (pull_request) Has been cancelled
Organize document URLs by category and collection with compact navigation
2026-10-28 18:38:13 +08:00

25 lines
978 B
TypeScript

import type { DocLink } from "@/lib/docs";
export function collectionLabel(name: string) {
return name.replace(/ 文档$| 源码教程$|问题集$/g, "");
}
export function collectionTone(name?: string) {
if (name?.includes("Pretext")) return "blue";
if (name?.includes("语言设计")) return "violet";
if (name?.includes("垃圾回收")) return "amber";
return "green";
}
export function collectionIcon(name?: string): "book" | "code" | "layers" | "nodes" {
if (name?.includes("Pretext")) return "code";
if (name?.includes("语言设计")) return "layers";
if (name?.includes("垃圾回收")) return "nodes";
return "book";
}
export function collectionEntries(docs: DocLink[]) {
return [...new Set(docs.map((doc) => doc.collection))].map((name) => {
const items = docs.filter((doc) => doc.collection === name);
const entry = items.find((doc) => doc.slug.endsWith("/overview")) ?? items[0];
return { name, entry, count: items.length };
});
}