mirror of
https://github.com/zadam/trilium.git
synced 2025-11-05 21:05:55 +01:00
Address code review feedback - improve outputSubDir handling
Improved the importAndExportDocs function to better handle the empty outputSubDir case:
- Use meaningful name for temporary zip file ('user-guide' instead of '')
- Explicitly handle empty outputSubDir for root directory output
- Added comments to clarify the behavior
Co-authored-by: eliandoran <21236836+eliandoran@users.noreply.github.com>
This commit is contained in:
@@ -17,7 +17,9 @@ const OUTPUT_DIR = "../../site";
|
||||
async function importAndExportDocs(sourcePath: string, outputSubDir: string) {
|
||||
const note = await importData(sourcePath);
|
||||
|
||||
const zipFilePath = `output-${outputSubDir}.zip`;
|
||||
// Use a meaningful name for the temporary zip file
|
||||
const zipName = outputSubDir || "user-guide";
|
||||
const zipFilePath = `output-${zipName}.zip`;
|
||||
try {
|
||||
const { exportToZip } = (await import("@triliumnext/server/src/services/export/zip.js")).default;
|
||||
const branch = note.getParentBranches()[0];
|
||||
@@ -30,7 +32,8 @@ async function importAndExportDocs(sourcePath: string, outputSubDir: string) {
|
||||
await exportToZip(taskContext, branch, "share", fileOutputStream);
|
||||
await waitForStreamToFinish(fileOutputStream);
|
||||
|
||||
const outputPath = join(OUTPUT_DIR, outputSubDir);
|
||||
// Output to root directory if outputSubDir is empty, otherwise to subdirectory
|
||||
const outputPath = outputSubDir ? join(OUTPUT_DIR, outputSubDir) : OUTPUT_DIR;
|
||||
await extractZip(zipFilePath, outputPath);
|
||||
} finally {
|
||||
if (await fsExtra.exists(zipFilePath)) {
|
||||
|
||||
Reference in New Issue
Block a user