@@ -192,21 +192,111 @@ export function filterDocsByPackage(
192
192
return filtered ;
193
193
}
194
194
195
- export function generateLlmContent ( filteredDocs : Record < string , string > , type : Package ) : string {
195
+ interface MinimizeOptions {
196
+ removeLegacy : boolean ;
197
+ removeNoteBlocks : boolean ;
198
+ removeDetailsBlocks : boolean ;
199
+ removePlaygroundLinks : boolean ;
200
+ removePrettierIgnore : boolean ;
201
+ normalizeWhitespace : boolean ;
202
+ }
203
+
204
+ const defaultOptions : MinimizeOptions = {
205
+ removeLegacy : false ,
206
+ removeNoteBlocks : false ,
207
+ removeDetailsBlocks : false ,
208
+ removePlaygroundLinks : false ,
209
+ removePrettierIgnore : false ,
210
+ normalizeWhitespace : false
211
+ } ;
212
+
213
+ function removeQuoteBlocks ( content : string , blockType : string ) : string {
214
+ return content
215
+ . split ( '\n' )
216
+ . reduce ( ( acc : string [ ] , line : string , index : number , lines : string [ ] ) => {
217
+ // If we find a block (with or without additional text), skip it and all subsequent blockquote lines
218
+ if ( line . trim ( ) . startsWith ( `> [!${ blockType } ]` ) ) {
219
+ // Skip all subsequent lines that are part of the blockquote
220
+ let i = index ;
221
+ while ( i < lines . length && ( lines [ i ] . startsWith ( '>' ) || lines [ i ] . trim ( ) === '' ) ) {
222
+ i ++ ;
223
+ }
224
+ // Update the index to skip all these lines
225
+ index = i - 1 ;
226
+ return acc ;
227
+ }
228
+
229
+ // Only add the line if it's not being skipped
230
+ acc . push ( line ) ;
231
+ return acc ;
232
+ } , [ ] )
233
+ . join ( '\n' ) ;
234
+ }
235
+
236
+ function minimizeContent ( content : string , options ?: Partial < MinimizeOptions > ) : string {
237
+ // Merge with defaults, but only for properties that are defined
238
+ const settings : MinimizeOptions = options ? { ...defaultOptions , ...options } : defaultOptions ;
239
+
240
+ let minimized = content ;
241
+
242
+ if ( settings . removeLegacy ) {
243
+ minimized = removeQuoteBlocks ( minimized , 'LEGACY' ) ;
244
+ }
245
+
246
+ if ( settings . removeNoteBlocks ) {
247
+ minimized = removeQuoteBlocks ( minimized , 'NOTE' ) ;
248
+ }
249
+
250
+ if ( settings . removeDetailsBlocks ) {
251
+ minimized = removeQuoteBlocks ( minimized , 'DETAILS' ) ;
252
+ }
253
+
254
+ if ( settings . removePlaygroundLinks ) {
255
+ // Replace playground URLs with /[link] but keep the original link text
256
+ minimized = minimized . replace ( / \[ ( [ ^ \] ] + ) \] \( \/ p l a y g r o u n d [ ^ ) ] + \) / g, '[$1](/REMOVED)' ) ;
257
+ }
258
+
259
+ if ( settings . removePrettierIgnore ) {
260
+ minimized = minimized
261
+ . split ( '\n' )
262
+ . filter ( ( line ) => line . trim ( ) !== '<!-- prettier-ignore -->' )
263
+ . join ( '\n' ) ;
264
+ }
265
+
266
+ if ( settings . normalizeWhitespace ) {
267
+ minimized = minimized . replace ( / \s + / g, ' ' ) ;
268
+ }
269
+
270
+ minimized = minimized . trim ( ) ;
271
+
272
+ return minimized ;
273
+ }
274
+
275
+ export function generateLlmContent (
276
+ filteredDocs : Record < string , string > ,
277
+ type : Package ,
278
+ minimizeOptions ?: Partial < MinimizeOptions >
279
+ ) : string {
196
280
let content = `<SYSTEM>${ getDocumentationTitle ( type ) } </SYSTEM>\n\n` ;
197
281
198
282
const paths = sortPaths ( Object . keys ( filteredDocs ) ) ;
199
283
200
284
for ( const path of paths ) {
201
285
content += `# ${ path . replace ( '../../../content/' , '' ) } \n\n` ;
202
- content += filteredDocs [ path ] ;
286
+ const docContent = minimizeOptions
287
+ ? minimizeContent ( filteredDocs [ path ] , minimizeOptions )
288
+ : filteredDocs [ path ] ;
289
+ content += docContent ;
203
290
content += '\n' ;
204
291
}
205
292
206
293
return content ;
207
294
}
208
295
209
- export function generateCombinedContent ( documentsContent : Record < string , string > ) : string {
296
+ export function generateCombinedContent (
297
+ documentsContent : Record < string , string > ,
298
+ minimizeOptions ?: Partial < MinimizeOptions >
299
+ ) : string {
210
300
let content = '' ;
211
301
let currentSection = '' ;
212
302
const paths = sortPaths ( Object . keys ( documentsContent ) ) ;
@@ -223,7 +313,10 @@ export function generateCombinedContent(documentsContent: Record<string, string>
223
313
}
224
314
225
315
content += `## ${ path . replace ( '../../../content/' , '' ) } \n\n` ;
226
- content += documentsContent [ path ] ;
316
+ const docContent = minimizeOptions
317
+ ? minimizeContent ( documentsContent [ path ] , minimizeOptions )
318
+ : documentsContent [ path ] ;
319
+ content += docContent ;
227
320
content += '\n' ;
228
321
}
229
322
0 commit comments