@@ -25,8 +25,6 @@ function extractPathFromUrl(url) {
2525function getUrlHierarchyDepth ( url ) {
2626 const urlPath = extractPathFromUrl ( url ) ;
2727 const segments = urlPath . split ( '/' ) . filter ( ( segment ) => segment && segment !== '' ) ;
28-
29- // Remove the .md file extension to count only directory levels
3028 const nonFileSegments = segments . filter ( ( segment ) => ! segment . endsWith ( '.md' ) ) ;
3129
3230 return nonFileSegments . length ;
@@ -40,7 +38,6 @@ function isMainSectionPage(url) {
4038 const segments = urlPath . split ( '/' ) . filter ( ( segment ) => segment && segment !== '' ) ;
4139
4240 // Main pages are those with only one segment (the .md file)
43- // or specific known main pages
4441 if ( segments . length === 1 ) {
4542 return true ;
4643 }
@@ -62,40 +59,36 @@ function getLinkIndentation(url) {
6259 return 0 ;
6360 }
6461
65- // Calculate hierarchy depth
6662 const depth = getUrlHierarchyDepth ( url ) ;
6763
6864 // The first level after main sections gets 1 level of indentation
6965 // Each subsequent level gets another level of indentation
70- return Math . min ( depth * INDENT_LEVEL , INDENT_LEVEL * 4 ) ; // Cap at 4 levels
66+ return Math . min ( depth * INDENT_LEVEL , INDENT_LEVEL * 4 ) ;
7167}
7268
7369/**
7470 * Determines the indentation level for a line based on its content type and URL.
7571 */
7672function getIndentationLevel ( line , lineIndex , allLines ) {
77- // Handle markdown headers
78- if ( line . startsWith ( '# ' ) ) {
79- return 0 ; // Main title - no indent
80- }
81-
82- if ( line . startsWith ( '## ' ) ) {
83- return 0 ; // Section title - no indent
73+ if ( line . startsWith ( '# ' ) || line . startsWith ( '## ' ) ) {
74+ return 0 ;
8475 }
8576
8677 if ( line . startsWith ( '### ' ) ) {
87- return INDENT_LEVEL ; // Subsection title - 1 level indent
78+ return INDENT_LEVEL ;
8879 }
8980
9081 if ( line . startsWith ( '#### ' ) ) {
91- return INDENT_LEVEL * 2 ; // Sub-subsection title - 2 level indent
82+ return INDENT_LEVEL * 2 ;
9283 }
9384
9485 // Handle markdown links with URLs
9586 if ( line . startsWith ( '- [' ) && line . includes ( `](${ BASE_URL } /` ) ) {
87+ // Extract URL from markdown link format: - [Link Text](https://docs.apify.com/path/to/page)
88+ // Example: "- [API Reference](https://docs.apify.com/api/v2)" → extracts "https://docs.apify.com/api/v2"
9689 const urlMatch = line . match ( new RegExp ( `\\]\\((${ BASE_URL . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) } /[^)]+)\\)` ) ) ;
9790 if ( ! urlMatch ) {
98- return INDENT_LEVEL ; // Fallback if URL parsing fails
91+ return INDENT_LEVEL ;
9992 }
10093 return getLinkIndentation ( urlMatch [ 1 ] ) ;
10194 }
@@ -121,7 +114,7 @@ function indentContent(content) {
121114 const line = lines [ i ] ;
122115 const trimmedLine = line . trim ( ) ;
123116
124- // Skip empty lines
117+ // Preserve empty lines (add them without indentation)
125118 if ( ! trimmedLine ) {
126119 indentedLines . push ( '' ) ;
127120 continue ;
@@ -156,7 +149,4 @@ async function indentLlmsFile() {
156149 }
157150}
158151
159- indentLlmsFile ( ) . catch ( ( err ) => {
160- console . error ( 'Failed to indent LLMs files:' , err ) ;
161- process . exit ( 1 ) ;
162- } ) ;
152+ await indentLlmsFile ( ) ;
0 commit comments