@@ -18,26 +18,17 @@ const redirects: Redirect[] = Object.entries(gitbookConfig.redirects ?? {}).map(
1818 ( [ source , target ] ) => ( { source, target } ) ,
1919)
2020
21- // Check if a path resolves to a page as a file, URL slug, or directory index.
2221function pageExists ( fullPath : string ) : boolean {
23- // Exact file match (e.g., quickstart.md) — must be a file, not a directory
2422 if ( existsSync ( fullPath ) && statSync ( fullPath ) . isFile ( ) ) return true
25- // URL-style target without .md extension (e.g., api/devices → api/devices.md)
2623 if ( ! fullPath . endsWith ( '.md' ) && existsSync ( fullPath + '.md' ) ) return true
27- // README.md targets resolve as directory URLs in GitBook, so check if the
28- // parent path resolves as a page (e.g., foo/README.md → foo.md).
2924 if ( fullPath . endsWith ( '/README.md' ) ) {
3025 const parentPath = fullPath . slice ( 0 , - '/README.md' . length )
3126 if ( existsSync ( parentPath + '.md' ) ) return true
3227 }
3328 return false
3429}
3530
36- // Resolve a redirect target to check it points to a real page.
37- // Targets may reference other site sections via URL prefix.
3831function resolveTarget ( target : string ) : boolean {
39- // Try matching against site sections by URL prefix (most specific first).
40- // The siteSections array is already ordered with more-specific prefixes first.
4132 for ( const section of siteSections ) {
4233 if ( section . urlPrefix === '' ) continue
4334
@@ -48,7 +39,6 @@ function resolveTarget(target: string): boolean {
4839 }
4940 }
5041
51- // Fall back to the default section (Guides, urlPrefix '')
5242 const guidesSection = siteSections . find ( ( s ) => s . urlPrefix === '' )
5343 if ( guidesSection == null ) return false
5444
0 commit comments