From 35b96c79a5dd9605ccd5b6b847a7d065c32477e2 Mon Sep 17 00:00:00 2001 From: Madison Date: Wed, 23 Jul 2025 20:06:26 -0500 Subject: [PATCH] revert broken changes --- docs/scripts/generate-platform-navigation.js | 27 +++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/docs/scripts/generate-platform-navigation.js b/docs/scripts/generate-platform-navigation.js index b61aec58a..8fd7c74d0 100644 --- a/docs/scripts/generate-platform-navigation.js +++ b/docs/scripts/generate-platform-navigation.js @@ -54,6 +54,16 @@ ${config.pages.map(page => { }).join('\n')} ]; +/** + * Safely join URL path segments + */ +function joinUrlPath(...segments: string[]): string { + return segments + .filter(segment => segment && segment.length > 0) + .join('/') + .replace(/\/+/g, '/'); // Remove duplicate slashes +} + /** * Check if a specific page exists for a given platform */ @@ -62,7 +72,17 @@ export function pageExistsForPlatform(path: string, platform: Platform): boolean const normalizedPath = path.replace(/^\\//, ''); const pathWithExt = normalizedPath.endsWith('.mdx') ? normalizedPath : \`\${normalizedPath}.mdx\`; - const page = PLATFORM_PAGES.find(p => p.path === pathWithExt); + // First try to find exact match + let page = PLATFORM_PAGES.find(p => p.path === pathWithExt); + + // If not found and path doesn't end with index, try appending /index.mdx + if (!page && !pathWithExt.includes('/index.mdx')) { + const indexPath = normalizedPath.endsWith('.mdx') + ? normalizedPath.replace('.mdx', '/index.mdx') + : joinUrlPath(normalizedPath, 'index.mdx'); + page = PLATFORM_PAGES.find(p => p.path === indexPath); + } + return page?.platforms.includes(platform) ?? false; } @@ -76,11 +96,12 @@ export function getSmartPlatformRedirect(currentPath: string, targetPlatform: Pl // If the exact same page exists for target platform, use it if (pageExistsForPlatform(pathWithoutPlatform, targetPlatform)) { - return \`/docs/\${targetPlatform}/\${pathWithoutPlatform.replace(/\\.mdx$/, '')}\`; + const cleanPath = pathWithoutPlatform.replace(/\\.mdx$/, ''); + return joinUrlPath('/docs', targetPlatform, cleanPath); } // Otherwise, redirect to overview - return \`/docs/\${targetPlatform}/overview\`; + return joinUrlPath('/docs', targetPlatform, 'overview'); } /**