mirror of
https://github.com/zadam/trilium.git
synced 2025-11-06 21:36:05 +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) {
|
async function importAndExportDocs(sourcePath: string, outputSubDir: string) {
|
||||||
const note = await importData(sourcePath);
|
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 {
|
try {
|
||||||
const { exportToZip } = (await import("@triliumnext/server/src/services/export/zip.js")).default;
|
const { exportToZip } = (await import("@triliumnext/server/src/services/export/zip.js")).default;
|
||||||
const branch = note.getParentBranches()[0];
|
const branch = note.getParentBranches()[0];
|
||||||
@@ -30,7 +32,8 @@ async function importAndExportDocs(sourcePath: string, outputSubDir: string) {
|
|||||||
await exportToZip(taskContext, branch, "share", fileOutputStream);
|
await exportToZip(taskContext, branch, "share", fileOutputStream);
|
||||||
await waitForStreamToFinish(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);
|
await extractZip(zipFilePath, outputPath);
|
||||||
} finally {
|
} finally {
|
||||||
if (await fsExtra.exists(zipFilePath)) {
|
if (await fsExtra.exists(zipFilePath)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user