@@ -165,46 +165,70 @@ function collectContent(rootDir, dirPath = rootDir) {
165165 return combined ;
166166}
167167
168- function getLastVersion ( ) {
168+ function getVersionConfig ( ) {
169169 const configPath = path . join ( __dirname , '..' , 'docusaurus.config.js' ) ;
170170 const configContent = fs . readFileSync ( configPath , 'utf8' ) ;
171- const match = configContent . match ( / l a s t V e r s i o n : \s * [ ' " ] ( [ ^ ' " ] + ) [ ' " ] / ) ;
172- return match ? match [ 1 ] : 'current' ;
171+
172+ const lastVersionMatch = configContent . match ( / l a s t V e r s i o n : \s * [ ' " ] ( [ ^ ' " ] + ) [ ' " ] / ) ;
173+ const lastVersion = lastVersionMatch ? lastVersionMatch [ 1 ] : 'current' ;
174+
175+ // Extract version paths from config
176+ const versions = { } ;
177+ const versionBlockMatch = configContent . match ( / v e r s i o n s : \s * \{ ( [ ^ } ] + ) \} / s) ;
178+ if ( versionBlockMatch ) {
179+ const versionBlock = versionBlockMatch [ 1 ] ;
180+ const currentPathMatch = versionBlock . match ( / c u r r e n t : \s * \{ [ ^ } ] * p a t h : \s * [ ' " ] ( [ ^ ' " ] * ) [ ' " ] / ) ;
181+ const v1xPathMatch = versionBlock . match ( / [ ' " ] 1 \. x [ ' " ] : \s * \{ [ ^ } ] * p a t h : \s * [ ' " ] ( [ ^ ' " ] * ) [ ' " ] / ) ;
182+
183+ versions . current = currentPathMatch ? currentPathMatch [ 1 ] : '' ;
184+ versions [ '1.x' ] = v1xPathMatch ? v1xPathMatch [ 1 ] : '' ;
185+ }
186+
187+ return { lastVersion, versions } ;
173188}
174189
175190function main ( ) {
176191 const buildDir = path . join ( __dirname , '..' , 'build' ) ;
177192 ensureDir ( buildDir ) ;
178193
179- const lastVersion = getLastVersion ( ) ;
194+ const { lastVersion, versions } = getVersionConfig ( ) ;
180195
181196 // Generate manifest for v1.x (versioned docs)
182197 const v1DocsDir = path . join ( __dirname , '..' , 'versioned_docs' , 'version-1.x' ) ;
198+ let v1Content = null ;
183199 if ( fs . existsSync ( v1DocsDir ) ) {
184- const v1Content = collectContent ( v1DocsDir ) . trimStart ( ) + '\n' ;
185- const v1OutputFile = path . join ( buildDir , 'llms-full-1.x.txt' ) ;
186- fs . writeFileSync ( v1OutputFile , v1Content , 'utf8' ) ;
187- console . log ( 'llms-full-1.x.txt generated successfully:' , v1OutputFile ) ;
200+ v1Content = collectContent ( v1DocsDir ) . trimStart ( ) + '\n' ;
201+ console . log ( 'Generated v1.x manifest' ) ;
188202 }
189203
190204 // Generate manifest for v2.0 (current docs)
191205 const v2DocsDir = path . join ( __dirname , '..' , 'docs' ) ;
206+ let v2Content = null ;
192207 if ( fs . existsSync ( v2DocsDir ) ) {
193- const v2Content = collectContent ( v2DocsDir ) . trimStart ( ) + '\n' ;
194- const v2OutputFile = path . join ( buildDir , 'llms-full-2.0.txt' ) ;
195- fs . writeFileSync ( v2OutputFile , v2Content , 'utf8' ) ;
196- console . log ( 'llms-full-2.0.txt generated successfully:' , v2OutputFile ) ;
208+ v2Content = collectContent ( v2DocsDir ) . trimStart ( ) + '\n' ;
209+ console . log ( 'Generated v2.0 manifest' ) ;
210+ }
211+
212+ // Write manifests to version-specific paths
213+ if ( v1Content && versions [ '1.x' ] ) {
214+ const v1Path = versions [ '1.x' ] ? path . join ( buildDir , versions [ '1.x' ] ) : buildDir ;
215+ ensureDir ( v1Path ) ;
216+ fs . writeFileSync ( path . join ( v1Path , 'llms-full.txt' ) , v1Content , 'utf8' ) ;
217+ console . log ( `v1.x manifest -> /${ versions [ '1.x' ] } /llms-full.txt` ) ;
197218 }
198219
199- // Copy the last version's manifest to llms-full.txt (canonical)
200- const canonicalSource = lastVersion === '1.x'
201- ? path . join ( buildDir , 'llms-full-1.x.txt' )
202- : path . join ( buildDir , 'llms-full-2.0.txt' ) ;
220+ if ( v2Content && versions . current ) {
221+ const v2Path = versions . current ? path . join ( buildDir , versions . current ) : buildDir ;
222+ ensureDir ( v2Path ) ;
223+ fs . writeFileSync ( path . join ( v2Path , 'llms-full.txt' ) , v2Content , 'utf8' ) ;
224+ console . log ( `v2.0 manifest -> /${ versions . current } /llms-full.txt` ) ;
225+ }
203226
204- const canonicalOutput = path . join ( buildDir , 'llms-full.txt' ) ;
205- if ( fs . existsSync ( canonicalSource ) ) {
206- fs . copyFileSync ( canonicalSource , canonicalOutput ) ;
207- console . log ( `llms-full.txt (canonical) copied from ${ lastVersion } manifest` ) ;
227+ // Write canonical manifest at root (based on lastVersion)
228+ const canonicalContent = lastVersion === '1.x' ? v1Content : v2Content ;
229+ if ( canonicalContent ) {
230+ fs . writeFileSync ( path . join ( buildDir , 'llms-full.txt' ) , canonicalContent , 'utf8' ) ;
231+ console . log ( `Canonical /llms-full.txt -> ${ lastVersion } content` ) ;
208232 }
209233}
210234
0 commit comments