Skip to content

Commit 7d3da16

Browse files
committed
getNavBarItems
1 parent 2916802 commit 7d3da16

File tree

91 files changed

+34
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+34
-15
lines changed

.vitepress/config.mts

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,47 +72,43 @@ export default defineConfig({
7272
text: 'Документация',
7373
items: [
7474
{ text: 'autumn', link: '/getting-started/about-autumn' },
75-
{ text: 'winow', link: '/winow/' },
76-
{ text: 'annotations', link: '/annotations/' },
77-
{ text: 'autumn-collections', link: '/autumn-collections/' },
75+
...getNavBarItems('products/', false, 'autumn'),
7876
]
7977
},
8078
{
8179
text: 'API',
8280
items: [
83-
{ text: 'autumn', link: '/api/autumn/' },
84-
{ text: 'annotations', link: '/api/annotations/' },
85-
{ text: 'autumn-collections', link: '/api/autumn-collections/' },
81+
...getNavBarItems('api/'),
8682
]
8783
},
8884
],
8985

9086
sidebar: {
9187
// products
9288
"/": getSidebar({
93-
contentRoot: contentRoot + 'products/autumn/',
89+
contentRoot: contentRoot + 'products/000-autumn/',
9490
contentDirs: [
9591
{ text: 'Начало работы', dir: 'getting-started' },
9692
{ text: 'Использование фреймворка', dir: 'framework-elements' },
9793
],
9894
collapsed: false,
9995
}),
10096
"/annotations/": getSidebar({
101-
contentRoot: contentRoot + 'products/annotations/',
97+
contentRoot: contentRoot + 'products/010-annotations/',
10298
contentDirs: [
10399
{ text: 'annotations', dir: '.' }
104100
],
105101
collapsed: false,
106102
}),
107103
"/autumn-collections/": getSidebar({
108-
contentRoot: contentRoot + 'products/autumn-collections/',
104+
contentRoot: contentRoot + 'products/020-autumn-collections/',
109105
contentDirs: [
110106
{ text: 'autumn-collections', dir: '.' }
111107
],
112108
collapsed: false,
113109
}),
114110
"/winow/": getSidebar({
115-
contentRoot: contentRoot + 'products/winow/',
111+
contentRoot: contentRoot + 'products/010-winow/',
116112
contentDirs: [
117113
{ text: 'winow', dir: '.' }
118114
],
@@ -122,14 +118,14 @@ export default defineConfig({
122118
"/api/autumn/": getSidebar({
123119
contentRoot,
124120
contentDirs: [
125-
{ text: 'autumn', dir: 'api/autumn' }
121+
{ text: 'autumn', dir: 'api/000-autumn' }
126122
],
127123
collapsed: false,
128124
}),
129125
"/api/annotations/": getSidebar({
130126
contentRoot,
131127
contentDirs: [
132-
{ text: 'annotations', dir: 'api/annotations' }
128+
{ text: 'annotations', dir: 'api/010-annotations' }
133129
],
134130
collapsed: false,
135131
}),
@@ -284,11 +280,34 @@ function getSidebarItem(contentRoot, file: string): DefaultTheme.SidebarItem {
284280
return sidebarItem;
285281
}
286282

287-
function getPageName(fileName: string) {
288-
return fileName
289-
.replace(/^\d+-/, '')
283+
function getPageName(fileName: string, doWordsSplit: boolean = true): string {
284+
const replacedFileName = fileName.replace(/^\d+-/, '');
285+
if (!doWordsSplit) return replacedFileName;
286+
287+
return replacedFileName
290288
.split('-')
291289
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
292290
.join(' ');
293291
}
294292

293+
function getNavBarItems(contentDir: string, appendNavBarWithContentDir: boolean = true, exclude: string = ''): DefaultTheme.NavItemWithLink[] {
294+
295+
const navBarItems: DefaultTheme.NavItemWithLink[] = [];
296+
const cwd = `${process.cwd()}/${contentRoot}`;
297+
298+
const dirs = glob.sync(`${contentDir}/*/`, { cwd }).sort();
299+
300+
for (const dirIndex in dirs) {
301+
const dir = dirs[dirIndex];
302+
303+
const text = getPageName(path.basename(dir), false);
304+
const link = appendNavBarWithContentDir ? `/${contentDir}/${text}/` : `/${text}/`;
305+
306+
if (text === exclude) continue;
307+
308+
navBarItems.push({ text, link });
309+
}
310+
311+
return navBarItems;
312+
313+
}

0 commit comments

Comments
 (0)