11import { minimatch } from 'minimatch' ;
22import { dev } from '$app/environment' ;
3- import { docs , index } from './content' ;
3+ import { index } from './content' ;
44
55interface GenerateLlmContentOptions {
66 prefix ?: string ;
77 ignore ?: string [ ] ;
88 minimize ?: Partial < MinimizeOptions > ;
9- package ?: string ;
9+ sections : Section [ ] ;
1010}
1111
1212interface MinimizeOptions {
@@ -18,6 +18,11 @@ interface MinimizeOptions {
1818 normalize_whitespace : boolean ;
1919}
2020
21+ interface Section {
22+ slug : string ;
23+ title : string ;
24+ }
25+
2126const defaults : MinimizeOptions = {
2227 remove_legacy : false ,
2328 remove_note_blocks : false ,
@@ -27,62 +32,48 @@ const defaults: MinimizeOptions = {
2732 normalize_whitespace : false
2833} ;
2934
30- export function generate_llm_content ( options : GenerateLlmContentOptions = { } ) : string {
35+ export function generate_llm_content ( options : GenerateLlmContentOptions ) : string {
3136 let content = '' ;
3237
3338 if ( options . prefix ) {
3439 content = `${ options . prefix } \n\n` ;
3540 }
3641
37- let current_section = '' ;
38- const paths = sort_documentation_paths ( ) ;
39-
40- for ( const path of paths ) {
41- if ( ! should_include_file_llm_docs ( path , options . ignore ) ) continue ;
42-
43- // If a specific package is provided, only include its docs
44- if ( options . package ) {
45- if ( ! path . includes ( `docs/${ options . package } /` ) ) continue ;
46- } else {
47- // For combined content, only include paths that match any package
48- const doc_type = packages . find ( ( p ) => path . includes ( `docs/${ p } /` ) ) ;
49- if ( ! doc_type ) continue ;
50-
51- const section = get_documentation_start_title ( doc_type ) ;
52- if ( section !== current_section ) {
53- if ( current_section ) content += '\n' ;
54- content += `${ section } \n\n` ;
55- current_section = section ;
56- }
42+ for ( const section of options . sections ) {
43+ if ( options . sections . length > 1 ) {
44+ content += `${ get_documentation_start_title ( section ) } \n\n` ;
5745 }
5846
59- const doc_content = options . minimize
60- ? minimize_content ( index [ path ] . body , options . minimize )
61- : index [ path ] . body ;
62- if ( doc_content . trim ( ) === '' ) continue ;
47+ for ( const [ path , document ] of Object . entries ( index ) ) {
48+ if ( ! path . startsWith ( `docs/${ section . slug } ` ) ) continue ;
49+ if ( ! should_include_file_llm_docs ( path , options . ignore ) ) continue ;
50+
51+ const doc_content = options . minimize
52+ ? minimize_content ( document . body , options . minimize )
53+ : document . body ;
54+ if ( doc_content . trim ( ) === '' ) continue ;
6355
64- content += `\n# ${ index [ path ] . metadata . title } \n\n` ;
65- content += doc_content ;
66- content += '\n' ;
56+ content += `\n# ${ document . metadata . title } \n\n` ;
57+ content += doc_content ;
58+ content += '\n' ;
59+ }
6760 }
6861
6962 return content ;
7063}
7164
72- export const packages = Object . keys ( docs . topics ) . map ( ( topic ) => topic . split ( '/' ) [ 1 ] ) ;
73-
74- export const DOCUMENTATION_NAMES : Record < string , string > = {
75- svelte : 'Svelte' ,
76- kit : 'SvelteKit' ,
77- cli : 'Svelte CLI'
78- } ;
65+ export const sections : Section [ ] = [
66+ { slug : 'svelte' , title : 'Svelte' } ,
67+ { slug : 'kit' , title : 'SvelteKit' } ,
68+ { slug : 'cli' , title : 'the Svelte CLI' }
69+ ] ;
7970
80- export function get_documentation_title ( type : string ) : string {
81- return `This is the developer documentation for ${ DOCUMENTATION_NAMES [ type ] } .` ;
71+ export function get_documentation_title ( section : Section ) : string {
72+ return `This is the developer documentation for ${ section . title } .` ;
8273}
8374
84- export function get_documentation_start_title ( type : string ) : string {
85- return `# Start of ${ DOCUMENTATION_NAMES [ type ] } documentation` ;
75+ export function get_documentation_start_title ( section : Section ) : string {
76+ return `# Start of ${ section . title } documentation` ;
8677}
8778
8879function minimize_content ( content : string , options ?: Partial < MinimizeOptions > ) : string {
@@ -133,38 +124,6 @@ function should_include_file_llm_docs(path: string, ignore: string[] = []): bool
133124 return true ;
134125}
135126
136- function get_documentation_section_priority ( path : string ) : number {
137- if ( path . includes ( 'docs/svelte/' ) ) return 0 ;
138- if ( path . includes ( 'docs/kit/' ) ) return 1 ;
139- if ( path . includes ( 'docs/cli/' ) ) return 2 ;
140- return 3 ;
141- }
142-
143- function sort_documentation_paths ( ) : string [ ] {
144- return Object . keys ( index ) . sort ( ( a , b ) => {
145- a = index [ a ] . file ;
146- b = index [ b ] . file ;
147- // First compare by section priority
148- const priorityA = get_documentation_section_priority ( a ) ;
149- const priorityB = get_documentation_section_priority ( b ) ;
150- if ( priorityA !== priorityB ) return priorityA - priorityB ;
151-
152- // Get directory paths
153- const dirA = a . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) ;
154- const dirB = b . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' ) ;
155-
156- // If in the same directory, prioritize index.md
157- if ( dirA === dirB ) {
158- if ( a . endsWith ( 'index.md' ) ) return - 1 ;
159- if ( b . endsWith ( 'index.md' ) ) return 1 ;
160- return a . localeCompare ( b ) ;
161- }
162-
163- // Otherwise sort by directory path
164- return dirA . localeCompare ( dirB ) ;
165- } ) ;
166- }
167-
168127function remove_quote_blocks ( content : string , blockType : string ) : string {
169128 return content
170129 . split ( '\n' )
0 commit comments