Skip to content

Commit f98cdbc

Browse files
Copilotnixel2007
andcommitted
Fix sidebar routing for single-page documentation: correct autumn-logos and autumn-collections sidebar matching
Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
1 parent 14f64f7 commit f98cdbc

File tree

1 file changed

+40
-19
lines changed

1 file changed

+40
-19
lines changed

.vitepress/config.mts

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -817,53 +817,74 @@ function processSinglePageDirectory(directory: string, baseRoute: string, rootOn
817817
function generateAllSidebarConfigurations(): DefaultTheme.SidebarMulti {
818818
const sidebarConfig: DefaultTheme.SidebarMulti = {};
819819

820-
// First add toggle mode single-page routes (most specific)
820+
// Get all individual sidebar configurations
821821
const toggleSidebars = getToggleModeSidebars();
822-
Object.assign(sidebarConfig, toggleSidebars);
823-
824-
// Then add regular single-page routes
825822
const singlePageSidebars = getSinglePageSidebars();
826-
Object.assign(sidebarConfig, singlePageSidebars);
827-
828-
// Add product routes
829823
const productSidebars = getSidebars('products/', false, 'autumn');
830-
Object.assign(sidebarConfig, productSidebars);
831-
832-
// Add API routes
833824
const apiSidebars = getSidebars('api/');
834-
Object.assign(sidebarConfig, apiSidebars);
835825

836-
// Add specific autumn framework routes
837-
sidebarConfig["/getting-started/"] = getSidebar({
826+
// Create ordered array of sidebar entries from most specific to least specific
827+
const sidebarEntries: [string, any][] = [];
828+
829+
// 1. Toggle mode single-page routes (most specific)
830+
for (const [route, sidebar] of Object.entries(toggleSidebars)) {
831+
sidebarEntries.push([route, sidebar]);
832+
}
833+
834+
// 2. Regular single-page routes (very specific)
835+
for (const [route, sidebar] of Object.entries(singlePageSidebars)) {
836+
sidebarEntries.push([route, sidebar]);
837+
}
838+
839+
// 3. Specific longer product and API routes first (autumn-collections before autumn)
840+
const allRoutes = [
841+
...Object.entries(productSidebars),
842+
...Object.entries(apiSidebars)
843+
];
844+
845+
// Sort by route length (descending) to ensure longer/more specific routes come first
846+
allRoutes.sort(([routeA], [routeB]) => routeB.length - routeA.length);
847+
848+
for (const [route, sidebar] of allRoutes) {
849+
sidebarEntries.push([route, sidebar]);
850+
}
851+
852+
// 4. Add specific autumn framework routes
853+
sidebarEntries.push(["/getting-started/", getSidebar({
838854
contentRoot: contentRoot + 'products/000-autumn/',
839855
contentDirs: [
840856
{ text: 'Начало работы', dir: 'getting-started' },
841857
{ text: 'Использование фреймворка', dir: 'framework-elements' },
842858
],
843859
collapsed: false,
844860
baseLink: ""
845-
});
861+
})]);
846862

847-
sidebarConfig["/framework-elements/"] = getSidebar({
863+
sidebarEntries.push(["/framework-elements/", getSidebar({
848864
contentRoot: contentRoot + 'products/000-autumn/',
849865
contentDirs: [
850866
{ text: 'Начало работы', dir: 'getting-started' },
851867
{ text: 'Использование фреймворка', dir: 'framework-elements' },
852868
],
853869
collapsed: false,
854870
baseLink: ""
855-
});
871+
})]);
856872

857-
// Finally add the root catch-all (least specific)
858-
sidebarConfig["/"] = getSidebar({
873+
// 5. Finally add the root catch-all (least specific)
874+
sidebarEntries.push(["/", getSidebar({
859875
contentRoot: contentRoot + 'products/000-autumn/',
860876
contentDirs: [
861877
{ text: 'Начало работы', dir: 'getting-started' },
862878
{ text: 'Использование фреймворка', dir: 'framework-elements' },
863879
],
864880
collapsed: false,
865881
baseLink: ""
866-
});
882+
})]);
883+
884+
// Build the final configuration maintaining order
885+
for (const [route, sidebar] of sidebarEntries) {
886+
sidebarConfig[route] = sidebar;
887+
}
867888

868889
return sidebarConfig;
869890
}

0 commit comments

Comments
 (0)