Skip to content

Commit 35b96c7

Browse files
committed
revert broken changes
1 parent a7acab4 commit 35b96c7

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

docs/scripts/generate-platform-navigation.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ ${config.pages.map(page => {
5454
}).join('\n')}
5555
];
5656
57+
/**
58+
* Safely join URL path segments
59+
*/
60+
function joinUrlPath(...segments: string[]): string {
61+
return segments
62+
.filter(segment => segment && segment.length > 0)
63+
.join('/')
64+
.replace(/\/+/g, '/'); // Remove duplicate slashes
65+
}
66+
5767
/**
5868
* Check if a specific page exists for a given platform
5969
*/
@@ -62,7 +72,17 @@ export function pageExistsForPlatform(path: string, platform: Platform): boolean
6272
const normalizedPath = path.replace(/^\\//, '');
6373
const pathWithExt = normalizedPath.endsWith('.mdx') ? normalizedPath : \`\${normalizedPath}.mdx\`;
6474
65-
const page = PLATFORM_PAGES.find(p => p.path === pathWithExt);
75+
// First try to find exact match
76+
let page = PLATFORM_PAGES.find(p => p.path === pathWithExt);
77+
78+
// If not found and path doesn't end with index, try appending /index.mdx
79+
if (!page && !pathWithExt.includes('/index.mdx')) {
80+
const indexPath = normalizedPath.endsWith('.mdx')
81+
? normalizedPath.replace('.mdx', '/index.mdx')
82+
: joinUrlPath(normalizedPath, 'index.mdx');
83+
page = PLATFORM_PAGES.find(p => p.path === indexPath);
84+
}
85+
6686
return page?.platforms.includes(platform) ?? false;
6787
}
6888
@@ -76,11 +96,12 @@ export function getSmartPlatformRedirect(currentPath: string, targetPlatform: Pl
7696
7797
// If the exact same page exists for target platform, use it
7898
if (pageExistsForPlatform(pathWithoutPlatform, targetPlatform)) {
79-
return \`/docs/\${targetPlatform}/\${pathWithoutPlatform.replace(/\\.mdx$/, '')}\`;
99+
const cleanPath = pathWithoutPlatform.replace(/\\.mdx$/, '');
100+
return joinUrlPath('/docs', targetPlatform, cleanPath);
80101
}
81102
82103
// Otherwise, redirect to overview
83-
return \`/docs/\${targetPlatform}/overview\`;
104+
return joinUrlPath('/docs', targetPlatform, 'overview');
84105
}
85106
86107
/**

0 commit comments

Comments
 (0)