@@ -17,6 +17,7 @@ import { convertSection } from './modules/convertSection';
1717import { convertStep } from './modules/convertStep' ;
1818import { removeHrAndLayout } from './modules/removeHrAndLayout' ;
1919import { removeIndentations } from './modules/removeIndentations' ;
20+ import { overviewByAI } from './modules/overviewByAI' ;
2021
2122import fs from 'fs' ;
2223import path from 'path' ;
@@ -103,37 +104,45 @@ function getRelativePath(filePath: string, basePath: string): string {
103104 return path . relative ( basePath , filePath ) . replace ( / \\ / g, '/' ) ;
104105}
105106
106- try {
107- const srcPagesPath = path . join ( process . cwd ( ) , '..' , 'src' , 'pages' ) ;
108- const outputDir = path . join ( process . cwd ( ) , '..' , 'public' , 'llms' ) ;
109- const allLinksPath = path . join ( process . cwd ( ) , '..' , 'public' , 'all-links-llms.txt' ) ;
110-
111- console . log ( `Searching for MDX files in: ${ srcPagesPath } ` ) ;
112-
113- const mdxFiles = findMdxFiles ( srcPagesPath ) ;
114-
115- if ( mdxFiles . length === 0 ) {
116- console . log ( 'No MDX files found in src/pages' ) ;
117- process . exit ( 1 ) ;
118- }
119-
120- console . log ( `Found ${ mdxFiles . length } MDX files` ) ;
121-
122- if ( ! fs . existsSync ( outputDir ) ) {
123- fs . mkdirSync ( outputDir , { recursive : true } ) ;
124- }
125-
126- // Array to store all the generated links
127- const allLinks : string [ ] = [ ] ;
128-
129- for ( const filePath of mdxFiles ) {
107+ async function main ( ) {
108+ try {
109+ const srcPagesPath = path . join ( process . cwd ( ) , '..' , 'src' , 'pages' ) ;
110+ const outputDir = path . join ( process . cwd ( ) , '..' , 'public' , 'llms' ) ;
111+ const allLinksPath = path . join ( process . cwd ( ) , '..' , 'public' , 'all-links-llms.txt' ) ;
112+
113+ console . log ( `Searching for MDX files in: ${ srcPagesPath } ` ) ;
114+
115+ const mdxFiles = findMdxFiles ( srcPagesPath ) ;
116+
117+ if ( mdxFiles . length === 0 ) {
118+ console . log ( 'No MDX files found in src/pages' ) ;
119+ process . exit ( 1 ) ;
120+ }
121+
122+ console . log ( `Found ${ mdxFiles . length } MDX files` ) ;
123+
124+ if ( ! fs . existsSync ( outputDir ) ) {
125+ fs . mkdirSync ( outputDir , { recursive : true } ) ;
126+ }
127+
128+ // Array to store all the generated links
129+ const allLinks : string [ ] = [ ] ;
130+
131+ for ( const filePath of mdxFiles ) {
130132 try {
131133 console . log ( `Processing: ${ filePath } ` ) ;
132134
133135 const mdxContent = readMdxFile ( filePath ) ;
134136
135137 const mdContent = convertMdxToMd ( mdxContent ) ;
136138
139+ // Extra step: Store the final MD output in informal_md variable
140+ const informal_md = mdContent ;
141+
142+ // Process with AI to get overview
143+ console . log ( `Processing with AI: ${ filePath } ` ) ;
144+ const aiProcessedContent = await overviewByAI ( informal_md ) ;
145+
137146 const relativePath = getRelativePath ( filePath , srcPagesPath ) ;
138147 const mdFileName = relativePath . replace ( / \. m d x $ / , '.md' ) ;
139148 const outputFilePath = path . join ( outputDir , mdFileName ) ;
@@ -157,7 +166,7 @@ try {
157166 // Add the "all links" section to the end of each MD file
158167 const finalMdContent =
159168 originalHeader +
160- mdContent +
169+ aiProcessedContent +
161170 '\n\n## all links\n\n[All links of docs](https://docs.liara.ir/all-links-llms.txt)\n' ;
162171
163172 // Write file with explicit UTF-8 encoding and BOM
@@ -189,10 +198,14 @@ try {
189198 fs . writeFileSync ( allLinksPath , '\ufeff' + allLinksContent , { encoding : 'utf8' } ) ;
190199 console . log ( `✅ All links saved to: ${ allLinksPath } ` ) ;
191200
192- console . log ( `All files converted and saved to: ${ outputDir } ` ) ;
193- console . log ( `Total files processed: ${ mdxFiles . length } ` ) ;
194-
195- } catch ( err ) {
196- console . error ( 'Error:' , err ) ;
197- process . exit ( 1 ) ;
201+ console . log ( `All files converted and saved to: ${ outputDir } ` ) ;
202+ console . log ( `Total files processed: ${ mdxFiles . length } ` ) ;
203+
204+ } catch ( err ) {
205+ console . error ( 'Error:' , err ) ;
206+ process . exit ( 1 ) ;
207+ }
198208}
209+
210+ // Run the main function
211+ main ( ) ;
0 commit comments