25 lines
978 B
TypeScript
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 };
|
|
});
|
|
}
|