@@ -14,17 +14,12 @@ import BuildContext from "./context.js";
1414const DOCS_ROOT = "../../../docs" ;
1515const OUTPUT_DIR = "../../site" ;
1616
17- async function buildDocsInner ( ) {
18- const i18n = await import ( "@triliumnext/server/src/services/i18n.js" ) ;
19- await i18n . initializeTranslations ( ) ;
20-
21- const sqlInit = ( await import ( "../../server/src/services/sql_init.js" ) ) . default ;
22- await sqlInit . createInitialDatabase ( true ) ;
23-
24- const note = await importData ( join ( __dirname , DOCS_ROOT , "User Guide" ) ) ;
17+ async function importAndExportDocs ( sourcePath : string , outputSubDir : string ) {
18+ const note = await importData ( sourcePath ) ;
2519
26- // Export
27- const zipFilePath = "output.zip" ;
20+ // Use a meaningful name for the temporary zip file
21+ const zipName = outputSubDir || "user-guide" ;
22+ const zipFilePath = `output-${ zipName } .zip` ;
2823 try {
2924 const { exportToZip } = ( await import ( "@triliumnext/server/src/services/export/zip.js" ) ) . default ;
3025 const branch = note . getParentBranches ( ) [ 0 ] ;
@@ -36,25 +31,50 @@ async function buildDocsInner() {
3631 const fileOutputStream = fsExtra . createWriteStream ( zipFilePath ) ;
3732 await exportToZip ( taskContext , branch , "share" , fileOutputStream ) ;
3833 await waitForStreamToFinish ( fileOutputStream ) ;
39- await extractZip ( zipFilePath , OUTPUT_DIR ) ;
34+
35+ // Output to root directory if outputSubDir is empty, otherwise to subdirectory
36+ const outputPath = outputSubDir ? join ( OUTPUT_DIR , outputSubDir ) : OUTPUT_DIR ;
37+ await extractZip ( zipFilePath , outputPath ) ;
4038 } finally {
4139 if ( await fsExtra . exists ( zipFilePath ) ) {
4240 await fsExtra . rm ( zipFilePath ) ;
4341 }
4442 }
43+ }
44+
45+ async function buildDocsInner ( ) {
46+ const i18n = await import ( "@triliumnext/server/src/services/i18n.js" ) ;
47+ await i18n . initializeTranslations ( ) ;
48+
49+ const sqlInit = ( await import ( "../../server/src/services/sql_init.js" ) ) . default ;
50+ await sqlInit . createInitialDatabase ( true ) ;
51+
52+ // Wait for becca to be loaded before importing data
53+ const beccaLoader = await import ( "../../server/src/becca/becca_loader.js" ) ;
54+ await beccaLoader . beccaLoaded ;
55+
56+ // Build User Guide
57+ console . log ( "Building User Guide..." ) ;
58+ await importAndExportDocs ( join ( __dirname , DOCS_ROOT , "User Guide" ) , "user-guide" ) ;
59+
60+ // Build Developer Guide
61+ console . log ( "Building Developer Guide..." ) ;
62+ await importAndExportDocs ( join ( __dirname , DOCS_ROOT , "Developer Guide" ) , "developer-guide" ) ;
4563
4664 // Copy favicon.
4765 await fs . copyFile ( "../../apps/website/src/assets/favicon.ico" , join ( OUTPUT_DIR , "favicon.ico" ) ) ;
66+ await fs . copyFile ( "../../apps/website/src/assets/favicon.ico" , join ( OUTPUT_DIR , "user-guide" , "favicon.ico" ) ) ;
67+ await fs . copyFile ( "../../apps/website/src/assets/favicon.ico" , join ( OUTPUT_DIR , "developer-guide" , "favicon.ico" ) ) ;
4868
4969 console . log ( "Documentation built successfully!" ) ;
5070}
5171
5272export async function importData ( path : string ) {
5373 const buffer = await createImportZip ( path ) ;
54- const importService = ( await import ( "@triliumnext /server/src/services/import/zip.js" ) ) . default ;
55- const TaskContext = ( await import ( "@triliumnext /server/src/services/task_context.js" ) ) . default ;
74+ const importService = ( await import ( "../.. /server/src/services/import/zip.js" ) ) . default ;
75+ const TaskContext = ( await import ( "../.. /server/src/services/task_context.js" ) ) . default ;
5676 const context = new TaskContext ( "no-progress-reporting" , "importNotes" , null ) ;
57- const becca = ( await import ( "@triliumnext /server/src/becca/becca.js" ) ) . default ;
77+ const becca = ( await import ( "../.. /server/src/becca/becca.js" ) ) . default ;
5878
5979 const rootNote = becca . getRoot ( ) ;
6080 if ( ! rootNote ) {
0 commit comments