@@ -25,19 +25,35 @@ const extractLinks = (content) => {
2525
2626// Check if a local file exists
2727const checkLocalFile = ( linkPath , filePath ) => {
28- if ( linkPath . startsWith ( '/docs/' ) ) {
28+ // Check for internal links (starting with / but not external URLs)
29+ if ( linkPath . startsWith ( '/' ) && ! linkPath . startsWith ( '//' ) && ! linkPath . startsWith ( 'http' ) ) {
2930 // Remove hash fragment before checking file existence
3031 const [ baseUrl ] = linkPath . split ( '#' ) ;
31- const localPath = path . join ( process . cwd ( ) , baseUrl ) ;
3232
33- try {
34- fs . accessSync ( localPath , fs . constants . F_OK ) ;
35- console . log ( ` ✅ ${ linkPath } ` ) ;
36- return true ;
37- } catch ( err ) {
38- console . log ( ` ❌ ${ linkPath } → File not found` ) ;
39- return false ;
33+ // Map the URL to the actual file location
34+ // Since our URLs are now root-level but files are in docs/
35+ const actualFilePath = path . join ( process . cwd ( ) , 'docs' , baseUrl . substring ( 1 ) ) ;
36+
37+ // Try both .mdx and .md extensions
38+ const possiblePaths = [
39+ actualFilePath + '.mdx' ,
40+ actualFilePath + '.md' ,
41+ path . join ( actualFilePath , 'index.mdx' ) ,
42+ path . join ( actualFilePath , 'index.md' )
43+ ] ;
44+
45+ for ( const possiblePath of possiblePaths ) {
46+ try {
47+ fs . accessSync ( possiblePath , fs . constants . F_OK ) ;
48+ console . log ( ` ✅ ${ linkPath } ` ) ;
49+ return true ;
50+ } catch ( err ) {
51+ // Continue to next possible path
52+ }
4053 }
54+
55+ console . log ( ` ❌ ${ linkPath } → File not found (checked: ${ possiblePaths . map ( p => path . relative ( process . cwd ( ) , p ) ) . join ( ', ' ) } )` ) ;
56+ return false ;
4157 }
4258 return null ; // not a local file
4359} ;
@@ -79,7 +95,8 @@ const processFile = async (filePath) => {
7995
8096 let allValid = true ;
8197 for ( const link of links ) {
82- if ( link . url . startsWith ( '/docs/' ) ) {
98+ if ( link . url . startsWith ( '/' ) && ! link . url . startsWith ( '//' ) && ! link . url . startsWith ( 'http' ) ) {
99+ // Internal link (root-level)
83100 const isValid = checkLocalFile ( link . url , filePath ) ;
84101 if ( ! isValid ) allValid = false ;
85102 } else if ( link . url . startsWith ( 'http' ) ) {
@@ -109,7 +126,7 @@ const processDirectory = async (dir) => {
109126 if ( stat . isDirectory ( ) ) {
110127 const isValid = await processDirectory ( filePath ) ;
111128 if ( ! isValid ) allValid = false ;
112- } else if ( file . endsWith ( '.md' ) ) {
129+ } else if ( file . endsWith ( '.md' ) || file . endsWith ( '.mdx' ) ) {
113130 const isValid = await processFile ( filePath ) ;
114131 if ( ! isValid ) allValid = false ;
115132 }
0 commit comments