mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-24 02:20:13 +01:00
🎨 Remove empty assets dir when exporting PDF https://github.com/siyuan-note/siyuan/issues/13670
This commit is contained in:
parent
77efc5cca4
commit
fa27f6c33f
1 changed files with 19 additions and 13 deletions
|
|
@ -322,29 +322,35 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%pa
|
|||
path: pdfFilePath,
|
||||
removeAssets: ipcData.removeAssets,
|
||||
watermark: ipcData.watermark
|
||||
}, () => {
|
||||
}, async () => {
|
||||
afterExport(pdfFilePath, msgId);
|
||||
if (ipcData.removeAssets) {
|
||||
const removePromise = (dir: string) => {
|
||||
return new Promise(function (resolve) {
|
||||
//先读文件夹
|
||||
fs.stat(dir, function (err, stat) {
|
||||
if (stat) {
|
||||
if (stat.isDirectory()) {
|
||||
fs.readdir(dir, function (err, files) {
|
||||
files = files.map(file => path.join(dir, file)); // a/b a/m
|
||||
Promise.all(files.map(file => removePromise(file))).then(function () {
|
||||
fs.rm(dir, resolve);
|
||||
});
|
||||
if (!stat) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (stat.isDirectory()) {
|
||||
fs.readdir(dir, function (err, files) {
|
||||
files = files.map(file => path.join(dir, file)); // a/b a/m
|
||||
Promise.all(files.map(file => removePromise(file))).then(function () {
|
||||
fs.rm(dir, resolve);
|
||||
});
|
||||
} else {
|
||||
fs.unlink(dir, resolve);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
fs.unlink(dir, resolve);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
removePromise(path.join(savePath, "assets"));
|
||||
|
||||
const assetsDir = path.join(savePath, "assets");
|
||||
await removePromise(assetsDir);
|
||||
if (1 > fs.readdirSync(assetsDir).length) {
|
||||
fs.rmdirSync(assetsDir);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue