From 3740b64483f1a8a7967ac83d320dc442d48a8c49 Mon Sep 17 00:00:00 2001 From: sinsombat Date: Sat, 16 May 2026 14:29:50 +0700 Subject: [PATCH] fix(core): remove implicit file-promotion in auto-router MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a folder contains .md files but no index.md, the auto-router designated the first file (alphabetically by title) as the folder-level index by overwriting its path with basePath. This had two problems: 1. Silent URL mismatch (fixed in the previous commit via the generator.ts trailing-slash fix) — the nav link pointed to the folder URL while the file was still output at its own path, producing a 404 on click. 2. Even when working correctly (after the generator.ts fix), the promotion drops the filename from the URL entirely: docs/SA/feature-discovery/my-doc.md → /SA/feature-discovery/ instead of the expected: docs/SA/feature-discovery/my-doc.md → /SA/feature-discovery/my-doc/ This creates inconsistent URL behaviour: files in folders WITH index.md keep their filename in the URL; files in folders WITHOUT index.md do not. It also makes it impossible to distinguish between two same-named files in sibling folders by URL alone. Fix: remove the promotion block so every .md file always generates a URL that includes its own filename, regardless of whether the parent folder has an index.md. Before: docs/SA/feature-discovery/my-doc.md → nav: /SA/feature-discovery → output: site/SA/feature-discovery/index.html After: docs/SA/feature-discovery/my-doc.md → nav: /SA/feature-discovery/my-doc/ → output: site/SA/feature-discovery/my-doc/index.html Impact: folders without index.md are rendered as collapsible section headers in the sidebar (no link) rather than having the first child file silently represent the section. This is more explicit and predictable. The _sourceFile field on nav items is no longer set; the corresponding navDesignatedIndexFiles logic in generator.ts becomes a no-op (harmless). --- packages/core/src/utils/auto-router.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/packages/core/src/utils/auto-router.ts b/packages/core/src/utils/auto-router.ts index 4e89d74..b3d0dc0 100644 --- a/packages/core/src/utils/auto-router.ts +++ b/packages/core/src/utils/auto-router.ts @@ -111,19 +111,6 @@ export function buildAutoNav(dir: string, basePath = '/'): any[] { // Default ba } } - // If no index exists at this level, and we have files, designate the first one as index - if (!indexExists && nav.length > 0) { - // Find first file (not a folder) - alphabetical after sorting (sorted below) - // But since sort hasn't happened yet, sort copies to pick the true first - const fileItems = nav.filter(n => !n.children).sort((a, b) => a.title.localeCompare(b.title)); - if (fileItems.length > 0) { - const firstFile = fileItems[0]; - // Store the original path before reassigning so the generator knows which file this is - firstFile._sourceFile = firstFile.path; - firstFile.path = basePath === '/' ? '/' : basePath; - } - } - // Sort: Put index.md (Home) at the top, then sort alphabetically return nav.sort((a, b) => { // Check if path effectively points to current folder root