-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsidebars.js
215 lines (196 loc) · 6.16 KB
/
sidebars.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// @ts-check
const fs = require('fs');
const path = require('path');
const matter = require('gray-matter');
/** Custom overrides for folder names */
const CustomNames = {
"type-aliases": "Types",
"interfaces": "Types",
"functions": "Functions",
"classes": "Classes",
"enumerations": "Enums",
"variables": "Variables",
};
function getFilesFromDirectory(dirPath, dirPathBase = '', baseDir = '', topLevelComponents = {}) {
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
const files = [];
const categories = [];
entries.forEach((entry) => {
const fullPath = path.join(dirPath, entry.name);
const relativePath = path.join(baseDir, entry.name);
const categoryLabel = CustomNames[entry.name] || entry.name.charAt(0).toUpperCase() + entry.name.slice(1);
if (entry.isDirectory()) {
const category = {
type: 'category',
collapsed: true,
label: categoryLabel,
items: getFilesFromDirectory(fullPath, (dirPathBase || dirPath), relativePath, topLevelComponents),
};
// Check if category already exists
const existingCategory = categories.find(c => c.label === categoryLabel);
if (existingCategory) {
existingCategory.items.push(...category.items);
}
else {
categories.push(category);
}
}
else if (entry.isFile() && (entry.name.endsWith('.md') || entry.name.endsWith('.mdx'))) {
if (entry.name === "README.md") {
/** Ignore auto generated README files. */
return;
}
const filePath = (dirPathBase || dirPath) + relativePath.replace(/\.mdx?$/, '').replace(/\\\\|\\/g, '/');
const fileContent = fs.readFileSync(fullPath, 'utf-8');
const { data } = matter(fileContent);
if (data.component) {
const componentName = data.component;
if (!topLevelComponents[componentName]) {
topLevelComponents[componentName] = {
type: 'category',
collapsed: true,
label: componentName,
items: [],
};
}
topLevelComponents[componentName].items.push(filePath);
}
else {
files.push(filePath);
}
}
});
// Filter out categories with no items
const filteredCategories = categories.filter(category => category.items.length > 0);
return [...files, ...filteredCategories];
}
function getFilesWithComponents(dirPath) {
const topLevelComponents = {};
const items = getFilesFromDirectory(path.join(__dirname, dirPath), dirPath.split("/").slice(1).join("/"), '', topLevelComponents);
return [...Object.values(topLevelComponents), ...items];
}
const steamBrewClient = getFilesWithComponents('ui/developers/plugins/typescript/client/');
const steamBrewWebkit = getFilesWithComponents('ui/developers/plugins/typescript/webkit/');
module.exports = {
homeSidebar: [
"about",
{
type: 'category',
label: 'User Documentation',
collapsed: false,
link: {
type: 'generated-index',
description:
'A Guide to Getting Acquainted with Millennium.',
slug: '/users',
},
items: [
'users/installing',
'users/uninstalling',
'users/getting-started',
'users/trouble-shooting',
'users/faq',
],
},
{
type: 'category',
label: 'Development',
collapsed: true,
link: {
type: 'generated-index',
description: "Let's learn about how to contribute to the Millennium community!",
slug: '/developers',
},
items: [
{
type: 'category',
label: 'Creating Themes',
collapsed: true,
link: {
type: 'generated-index',
description:
"Creating themes for Millennium is a fun and rewarding experience. Let's get started!",
slug: '/developers/themes',
},
items: [
'developers/themes/getting-started',
'developers/themes/making-themes',
'developers/themes/dynamic-patching',
'developers/themes/theme-colors',
'developers/themes/tips-and-tricks',
'developers/themes/publishing',
],
},
{
type: 'category',
label: 'Creating Plugins',
collapsed: true,
link: {
type: 'generated-index',
description: "Creating plugins for Millennium is a fun and rewarding experience. Let's get started!",
slug: '/developers/plugins',
},
items: [
'developers/plugins/learn',
'developers/plugins/packages',
{
type: 'category',
label: 'Python Reference',
collapsed: true,
link: {
type: 'generated-index',
description: "Creating plugins for Millennium is a fun and rewarding experience. Let's get started!",
slug: '/developers/plugins/python',
},
items: [
'developers/plugins/python/ready',
'developers/plugins/python/steam-path',
'developers/plugins/python/call-method',
'developers/plugins/python/add-css',
'developers/plugins/python/add-js',
'developers/plugins/python/remove-module',
'developers/plugins/python/set-setting',
'developers/plugins/python/user-settings',
'developers/plugins/python/version'
],
},
{
type: 'category',
label: 'TypeScript Reference',
collapsed: true,
link: {
type: 'generated-index',
description: "Creating plugins for Millennium is a fun and rewarding experience. Let's get started!",
slug: '/developers/plugins/typescript',
},
items: [
{
type: 'category',
label: '@steambrew/client',
collapsed: true,
link: {
type: 'generated-index',
description: "A plugin utility library for the client side of Steam.",
slug: '/developers/plugins/typescript/client',
},
items: steamBrewClient,
},
{
type: 'category',
label: '@steambrew/webkit',
collapsed: true,
link: {
type: 'generated-index',
description: "A plugin utility library for the web/server side of Steam.",
slug: '/developers/plugins/typescript/webkit',
},
items: steamBrewWebkit,
}
]
}
],
}
],
}
]
};