Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 8f30013

Browse files
avenue68vowstar
authored andcommitted
fix #23
1 parent 503651b commit 8f30013

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ function processBlock(blk) {
3333

3434
var assetPath = ASSET_PATH;
3535
var filePath = assetPath + crypto.createHash('sha1').update(code).digest('hex') + '.' + format;
36+
var rootPath = book.output.root();
37+
var destFilePath = path.join(rootPath, assetPath);
3638

3739
if (this.ctx && this.ctx.ctx && this.ctx.ctx.file && this.ctx.ctx.file.path) {
3840
var includePath = path.resolve(path.dirname(this.ctx.ctx.file.path));
@@ -48,7 +50,7 @@ function processBlock(blk) {
4850
}
4951
}
5052

51-
if (fs.existsSync(filePath)) {
53+
if (fs.existsSync(filePath) && fs.existsSync(destFilePath)) {
5254
var result = "<img src=/" + filePath + ">";
5355
deferred.resolve(result);
5456
} else {
@@ -64,17 +66,14 @@ function processBlock(blk) {
6466

6567
fs.writeFileSync(filePath, buffer, function(err) {
6668
if (err)
67-
console.error(err);
69+
console.error(err);
6870
});
6971

7072
var result = "<img src=/" + filePath + ">";
7173

7274
// NOTE: fix https://github.com/vowstar/gitbook-plugin-uml/issues/17
7375
// To make sure the asserts always copied before pdf generation
7476
// Copy images to output folder every time
75-
var output = book.output;
76-
var rootPath = output.root();
77-
var destFilePath = path.join(rootPath, assetPath);
7877
if (fs.existsSync(assetPath)) {
7978
// NOTE: fix https://github.com/vowstar/gitbook-plugin-uml/issues/22
8079
// When destFilePath exist, file should copied

0 commit comments

Comments
 (0)