@@ -3,6 +3,7 @@ import fsSync from 'fs';
3
3
import path from 'path' ;
4
4
import { fileURLToPath } from 'url' ;
5
5
import { parseFrontmatter , cleanReplComments } from '../src/lib/frontmatter.js' ;
6
+ import { v10StructuredDocRoutes } from '../src/lib/route-utils.js' ;
6
7
7
8
const __filename = fileURLToPath ( import . meta. url ) ;
8
9
const __dirname = path . dirname ( __filename ) ;
@@ -42,29 +43,42 @@ Preact is a fast, lightweight alternative to React that provides the same modern
42
43
43
44
let content = header ;
44
45
45
- files . sort ( ( a , b ) => a . filename . localeCompare ( b . filename ) ) ;
46
+ for ( const section of v10StructuredDocRoutes ) {
47
+ content += `## ${ section . name } \n\n` ;
46
48
47
- files . forEach ( ( { filename, content : fileContent } ) => {
48
- const { description, body } = parseFrontmatter ( fileContent , filename ) ;
49
- let cleanedBody = cleanReplComments ( body ) ;
49
+ for ( const route of section . routes ) {
50
+ const { filename, content : fileContent } = files . find (
51
+ file => file . filename === `${ route . replace ( '/' , '' ) } .md`
52
+ ) ;
50
53
51
- // Remove <toc></toc> tags
52
- cleanedBody = cleanedBody . replace ( / < t o c > < \/ t o c > / g , '' ) ;
54
+ const { description , body } = parseFrontmatter ( fileContent , filename ) ;
55
+ let cleanedBody = cleanReplComments ( body ) ;
53
56
54
- // Clean up multiple consecutive newlines and empty lines around separators
55
- cleanedBody = cleanedBody . replace ( / \n { 3 , } / g, '\n\n' ) ;
56
- cleanedBody = cleanedBody . replace ( / - - - \s * \n \s * \n \s * - - - / g, '' ) ;
57
+ // Remove <toc></toc> tags
58
+ cleanedBody = cleanedBody . replace ( / < t o c > < \/ t o c > / g, '' ) ;
57
59
58
- // Fix heading hierarchy: convert # to ## for consistency
59
- cleanedBody = cleanedBody . replace ( / ^ # / gm, '## ' ) ;
60
+ // Clean up multiple consecutive newlines and empty lines around separators
61
+ cleanedBody = cleanedBody . replace ( / \n { 3 , } / g, '\n\n' ) ;
62
+ cleanedBody = cleanedBody . replace ( / - - - \s * \n \s * \n \s * - - - / g, '' ) ;
60
63
61
- if ( description ) {
62
- content += `**Description:** ${ description } \n\n` ;
63
- }
64
+ // Fix heading hierarchy: page headings should be 3 levels deep to accommodate
65
+ // the llms document heading & the section headings for page/concept groups.
66
+ cleanedBody = cleanedBody
67
+ . replace ( / ^ # # # # / gm, '###### ' )
68
+ . replace ( / ^ # # # / gm, '##### ' )
69
+ . replace ( / ^ # # / gm, '#### ' )
70
+ // Not `/g` as there should only be one top-level heading per file
71
+ // and this would conflict with bash comments that we have in a few places.
72
+ . replace ( / ^ # / m, '### ' ) ;
73
+
74
+ if ( description ) {
75
+ content += `**Description:** ${ description } \n\n` ;
76
+ }
64
77
65
- content += `${ cleanedBody } \n\n` ;
66
- content += `------\n\n` ;
67
- } ) ;
78
+ content += `${ cleanedBody } \n\n` ;
79
+ content += `------\n\n` ;
80
+ }
81
+ }
68
82
69
83
return content ;
70
84
}
0 commit comments