@@ -18,6 +18,8 @@ interface BookConfig {
1818export interface GeneratePdfOptions {
1919 lang : string ;
2020 theme : string ;
21+ chapters ?: string [ ] ;
22+ note ?: string ;
2123}
2224
2325function parseArgs ( argv : string [ ] ) : GeneratePdfOptions {
@@ -95,12 +97,46 @@ export async function generatePdf(
9597 const startTime = Date . now ( ) ;
9698 console . log ( `[${ lang } ] Generating PDF...` ) ;
9799
98- const navigation = bookConfig . navigation [ lang ] ;
100+ let navigation = bookConfig . navigation [ lang ] ;
99101 if ( ! navigation ) {
100102 console . warn ( `[${ lang } ] No navigation found, skipping` ) ;
101103 continue ;
102104 }
103105
106+ // Filter chapters if --chapters option is specified
107+ const chapterFilter = args . chapters ?. filter ( ( c ) => c . length > 0 ) ;
108+ if ( chapterFilter && chapterFilter . length > 0 ) {
109+ const filterSet = new Set ( chapterFilter ) ;
110+ const filtered = navigation . filter ( ( nav ) => {
111+ const noExt = nav . path . replace ( / \. m d $ / , '' ) ;
112+ const segments = noExt . split ( '/' ) ;
113+ const pathStem = segments [ segments . length - 1 ] ;
114+ const dirName = segments . length > 1 ? segments [ segments . length - 2 ] : '' ;
115+ return (
116+ filterSet . has ( nav . path ) ||
117+ filterSet . has ( pathStem ) ||
118+ ( dirName !== '' && filterSet . has ( dirName ) )
119+ ) ;
120+ } ) ;
121+ if ( filtered . length === 0 ) {
122+ const available = navigation
123+ . map ( ( n ) => n . path . replace ( / \. m d $ / , '' ) . split ( '/' ) . pop ( ) )
124+ . join ( ', ' ) ;
125+ console . error (
126+ `[${ lang } ] No chapters matched filter: ${ chapterFilter . join ( ', ' ) } ` ,
127+ ) ;
128+ console . error (
129+ `[${ lang } ] Chapter identifiers can be a full path (e.g. overview/overview.md), directory name, or filename.` ,
130+ ) ;
131+ console . error ( `[${ lang } ] Available chapters: ${ available } ` ) ;
132+ process . exit ( 1 ) ;
133+ }
134+ navigation = filtered ;
135+ console . log (
136+ `[${ lang } ] Filtered to ${ navigation . length } chapter(s): ${ navigation . map ( ( n ) => n . title ) . join ( ', ' ) } ` ,
137+ ) ;
138+ }
139+
104140 // Process markdown files
105141 console . log ( `[${ lang } ] Processing ${ navigation . length } chapters...` ) ;
106142 const chapters = await processMarkdownFiles (
@@ -115,7 +151,7 @@ export async function generatePdf(
115151 console . log ( `[${ lang } ] Building HTML...` ) ;
116152 const html = buildFullDocument (
117153 chapters ,
118- { title, version, lang } ,
154+ { title, version, lang, note : args . note } ,
119155 config ,
120156 theme ,
121157 ) ;
0 commit comments