-
Notifications
You must be signed in to change notification settings - Fork 91
/
routes.ts
348 lines (341 loc) · 8.76 KB
/
routes.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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
import { Sidebar, SidebarItem } from "vocs";
const config: Sidebar = [
{
text: "Introduction",
link: "/",
},
{
text: "Getting Started",
items: [
// {
// text: "Local environment setup"
// },
{
text: "Basics of a Starknet contract",
items: [
{
text: "Storage",
link: "/getting-started/basics/storage",
},
{
text: "Constructor",
link: "/getting-started/basics/constructor",
},
{
text: "Variables",
link: "/getting-started/basics/variables",
},
{
text: "Visibility and Mutability",
link: "/getting-started/basics/visibility-mutability",
},
{
text: "Counter Example",
link: "/getting-started/basics/counter",
},
{
text: "Mappings",
link: "/getting-started/basics/mappings",
},
{
text: "Errors",
link: "/getting-started/basics/errors",
},
{
text: "Events",
link: "/getting-started/basics/events",
},
{
text: "Syscalls",
link: "/getting-started/basics/syscalls",
},
{
text: "Strings and ByteArrays",
link: "/getting-started/basics/bytearrays-strings",
},
{
text: "Storing Custom Types",
link: "/getting-started/basics/storing-custom-types",
},
{
text: "Custom types in entrypoints",
link: "/getting-started/basics/custom-types-in-entrypoints",
},
{
text: "Documentation",
link: "/getting-started/basics/documentation",
},
],
},
{
text: "Deploy and interact with contracts",
items: [
{
text: "How to deploy",
link: "/getting-started/interacting/how_to_deploy",
},
{
text: "Contract interfaces and Traits generation",
link: "/getting-started/interacting/interfaces-traits",
},
{
text: "Calling other contracts",
link: "/getting-started/interacting/calling_other_contracts",
},
{
text: "Factory pattern",
link: "/getting-started/interacting/factory",
},
],
},
{
text: "Testing contracts",
link: "/getting-started/testing/contract-testing",
},
],
},
{
text: "Components",
items: [
{
text: "Components How-To",
link: "/components/how_to",
},
{
text: "Components Dependencies",
link: "/components/dependencies",
},
{
text: "Storage Collisions",
link: "/components/collisions",
},
{
text: "Ownable",
link: "/components/ownable",
},
],
},
{
text: "Applications",
items: [
{
text: " Upgradeable Contract",
link: "/applications/upgradeable_contract",
},
{
text: "Defi Vault",
link: "/applications/simple_vault",
},
{
text: "ERC20 Token",
link: "/applications/erc20",
},
{
text: "NFT Dutch Auction",
link: "/applications/nft_dutch_auction",
},
{
text: "Constant Product AMM",
link: "/applications/constant-product-amm",
},
{
text: "TimeLock",
link: "/applications/timelock",
},
{
text: "Staking",
link: "/applications/staking",
},
{
text: "Merkle Tree",
link: "/applications/merkle_tree",
},
{
text: "Simple Storage with Starknet-js",
link: "/applications/simple_storage_starknetjs",
},
{
text: "Crowdfunding Campaign",
link: "/applications/crowdfunding",
},
{
text: "AdvancedFactory: Crowdfunding",
link: "/applications/advanced_factory",
},
{
text: "Random Number Generator",
link: "/applications/random_number_generator",
},
],
},
{
text: "Advanced concepts",
items: [
{
text: "Writing to any storage slot",
link: "/advanced-concepts/write_to_any_slot",
},
{
text: "Struct as mapping key",
link: "/advanced-concepts/struct-mapping-key",
},
{
text: "Hashing",
link: "/advanced-concepts/hashing",
},
// Hidden until #123 is solved
// {
// text: "Hash Solidity Compatible",
// link: "/advanced-concepts/hash-solidity-compatible"
// },
{
text: "Optimisations",
items: [
{
text: "Storage Optimisations",
link: "/advanced-concepts/optimisations/store_using_packing",
},
],
},
// Hidden as the content is not 100% correct
// {
// text: "Account Abstraction",
// items: [
// {
// text: "AA on Starknet",
// link: "/advanced-concepts/account_abstraction",
// },
// {
// text: "Account Contract",
// link: "/advanced-concepts/account_abstraction/account_contract",
// },
// ],
// },
{
text: "Library Calls",
link: "/advanced-concepts/library_calls",
},
{
text: "Plugins",
link: "/advanced-concepts/plugins",
},
{
text: "Signature Verification",
link: "/advanced-concepts/signature_verification",
},
],
},
{
text: "Cairo cheatsheet",
collapsed: true,
items: [
{
text: "Felt",
link: "/cairo_cheatsheet/felt",
},
{
text: "Map",
link: "/cairo_cheatsheet/mapping",
},
{
text: "Arrays",
link: "/cairo_cheatsheet/arrays",
},
{
text: "loop",
link: "/cairo_cheatsheet/loop",
},
{
text: "while",
link: "/cairo_cheatsheet/while",
},
{
text: "if let",
link: "/cairo_cheatsheet/if_let",
},
{
text: "while let",
link: "/cairo_cheatsheet/while_let",
},
{
text: "Enums",
link: "/cairo_cheatsheet/enums",
},
{
text: "Match",
link: "/cairo_cheatsheet/match",
},
{
text: "Tuples",
link: "/cairo_cheatsheet/tuples",
},
{
text: "Struct",
link: "/cairo_cheatsheet/struct",
},
{
text: "Type casting",
link: "/cairo_cheatsheet/type_casting",
},
{
text: "Dict",
link: "/cairo_cheatsheet/dict",
},
],
},
];
/**
* Gets all top-level routes from the sidebar config
* @param sidebar
* @returns Array of route paths and their corresponding section names
*/
const getTopLevelRoutes = (sidebar: SidebarItem[]): Array<[string, string]> =>
sidebar
.filter((item) => item.text !== "Introduction") // Skip Introduction
.map((item) => {
// Convert the text to a URL-friendly format and get the first link if available
const path =
item.link || `/${item.text.toLowerCase().replace(/\s+/g, "-")}`;
return [path.split("/")[1], item.text] as [string, string];
});
/**
* Generates a complete sidebar configuration with automatic route-based collapsing
* @param sidebar
* @returns Complete sidebar configuration object with route-specific collapsed states
*/
const generateSidebarConfig = (sidebar: SidebarItem[]): Sidebar => {
// Initialize with the default route
const config: Sidebar = {
"/": sidebar,
};
// Configure for all top-level routes
getTopLevelRoutes(sidebar).forEach(([route, sectionName]) => {
config[`/${route}`] = sidebarFocusOn(sidebar, sectionName, true);
});
return config;
};
/**
* Recursively modifies the sidebar structure to control which sections are collapsed
* @param sidebar - The original sidebar configuration array
* @param target - The section text to keep expanded (uncollapsed)
* @param closeOther - Whether to force collapse all non-target sections
* @returns Modified sidebar array with controlled collapsed states
*/
const sidebarFocusOn = (
sidebar: SidebarItem[],
target: string,
closeOther: boolean = false
): SidebarItem[] =>
sidebar.map((item) =>
item.items && item.items.length > 0
? {
...item,
collapsed: closeOther ? true : item.collapsed,
items: sidebarFocusOn(item.items, target, closeOther),
}
: {
...item,
collapsed: item.text === target ? item.collapsed : true,
}
);
export const routes = generateSidebarConfig(config);