forked from duddud11/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.ts
More file actions
72 lines (64 loc) · 1.52 KB
/
content.ts
File metadata and controls
72 lines (64 loc) · 1.52 KB
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
65
66
67
68
69
70
71
72
import { MDXRemoteSerializeResult } from 'next-mdx-remote';
// The frontmatter that all files are expected to have.
//
// Some files may have more as defined by their page implementations.
export interface Frontmatter {
title: string;
children?: string[];
}
export interface GraphQL {
document: string;
version: 'v1' | 'v2';
}
export interface REST {
method: 'GET' | 'POST';
url: string;
body?: string;
}
export interface Heading {
id: string;
text: string;
rank: number;
}
export interface Content {
frontmatter: Frontmatter;
source: MDXRemoteSerializeResult;
path: string;
filePath: string;
graphql: GraphQL[];
rest: REST[];
headings: Heading[];
links: Set<string>;
}
export function canonicalContentPath(p: string): string {
const parts = p.split('/');
if (parts.length === 0 || parts[0] !== '') {
parts.unshift('');
}
for (let i = 1; i < parts.length; i++) {
if (parts[i] === '.') {
parts.splice(i, 1);
i--;
} else if (parts[i] === '..') {
parts.splice(i - 1, 2);
i -= 2;
}
}
if (parts.length > 0 && parts[parts.length - 1] === '') {
parts.pop();
}
if (parts.length < 2) {
return '/';
}
return parts.join('/');
}
export interface TableOfContentsPage {
path: string;
title: string;
children?: TableOfContentsPage[];
}
export interface TableOfContents {
pages: TableOfContentsPage[];
path: string;
title: string;
}