Skip to content

Commit 44ac4b1

Browse files
committed
Автосайдбар
1 parent e5506ee commit 44ac4b1

File tree

1 file changed

+30
-44
lines changed

1 file changed

+30
-44
lines changed

.vitepress/config.mts

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -93,50 +93,8 @@ export default defineConfig({
9393
],
9494
collapsed: false,
9595
}),
96-
"/annotations/": getSidebar({
97-
contentRoot: contentRoot + 'products/010-annotations/',
98-
contentDirs: [
99-
{ text: 'annotations', dir: '.' }
100-
],
101-
collapsed: false,
102-
}),
103-
"/autumn-collections/": getSidebar({
104-
contentRoot: contentRoot + 'products/020-autumn-collections/',
105-
contentDirs: [
106-
{ text: 'autumn-collections', dir: '.' }
107-
],
108-
collapsed: false,
109-
}),
110-
"/winow/": getSidebar({
111-
contentRoot: contentRoot + 'products/010-winow/',
112-
contentDirs: [
113-
{ text: 'winow', dir: '.' }
114-
],
115-
collapsed: false,
116-
}),
117-
// api
118-
"/api/autumn/": getSidebar({
119-
contentRoot,
120-
contentDirs: [
121-
{ text: 'autumn', dir: 'api/000-autumn' }
122-
],
123-
collapsed: false,
124-
}),
125-
"/api/annotations/": getSidebar({
126-
contentRoot,
127-
contentDirs: [
128-
{ text: 'annotations', dir: 'api/010-annotations' }
129-
],
130-
collapsed: false,
131-
}),
132-
"/api/autumn-collections/": getSidebar({
133-
contentRoot,
134-
contentDirs: [
135-
{ text: 'autumn-collections', dir: 'api/autumn-collections' }
136-
],
137-
collapsed: false,
138-
}),
139-
96+
...getSidebars('products/', false, 'autumn'),
97+
...getSidebars('api/'),
14098
},
14199

142100
socialLinks: [
@@ -209,6 +167,34 @@ interface SidebarOptions {
209167
collapsed: boolean;
210168
}
211169

170+
function getSidebars(contentDir: string, appendSideBarWithContentDir: boolean = true, excluded: string = ''): DefaultTheme.SidebarMulti {
171+
172+
const sidebars: DefaultTheme.SidebarMulti = {};
173+
174+
const cwd = `${process.cwd()}/${contentRoot}`;
175+
176+
const dirs = glob.sync(`${contentDir}/*/`, { cwd }).sort();
177+
for (const dirIndex in dirs) {
178+
const dir = dirs[dirIndex];
179+
180+
const text = getPageName(path.basename(dir), false);
181+
const link = appendSideBarWithContentDir ? `/${contentDir}${text}/` : `/${text}/`;
182+
183+
if (text === excluded) continue;
184+
185+
sidebars[link] = getSidebar({
186+
contentRoot: contentRoot + dir + '/',
187+
contentDirs: [
188+
{ text, dir: "." }
189+
],
190+
collapsed: false,
191+
});
192+
}
193+
194+
return sidebars;
195+
196+
}
197+
212198
function getSidebar({ contentRoot, contentDirs, collapsed }: SidebarOptions): DefaultTheme.SidebarItem[] {
213199
const sidebar: DefaultTheme.SidebarItem[] = [];
214200

0 commit comments

Comments
 (0)