-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
docs.ts
64 lines (56 loc) · 1.56 KB
/
docs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import RAW_TOC from "../../docs/table-of-contents.json" with { type: "json" };
type RawTableOfContents = Record<string, RawTableOfContentsEntry>;
interface RawTableOfContentsEntry {
title: string;
pages?: [string, string][];
}
export interface TableOfContentsEntry {
slug: string;
title: string;
category?: string;
href: string;
file: string;
}
export interface TableOfContentsCategory {
title: string;
href: string;
entries: TableOfContentsCategoryEntry[];
}
export interface TableOfContentsCategoryEntry {
title: string;
href: string;
}
export const TABLE_OF_CONTENTS: Record<string, TableOfContentsEntry> = {};
export const CATEGORIES: TableOfContentsCategory[] = [];
for (const parent in (RAW_TOC as unknown as RawTableOfContents)) {
const rawEntry = (RAW_TOC as unknown as RawTableOfContents)[parent];
const href = `/docs/${parent}`;
const file = `docs/${parent}/index.md`;
const entry = {
slug: parent,
title: rawEntry.title,
href,
file,
};
TABLE_OF_CONTENTS[parent] = entry;
const category: TableOfContentsCategory = {
title: rawEntry.title,
href,
entries: [],
};
CATEGORIES.push(category);
if (rawEntry.pages) {
for (const [id, title] of rawEntry.pages) {
const slug = `${parent}/${id}`;
const href = `/docs/${slug}`;
const file = `docs/${slug}.md`;
const entry = { slug, title, category: parent, href, file };
TABLE_OF_CONTENTS[slug] = entry;
category.entries.push({
title,
href,
});
}
}
}
export const SLUGS = Object.keys(TABLE_OF_CONTENTS);