diff options
Diffstat (limited to 'lib/utils')
-rw-r--r-- | lib/utils/command.js | 2 | ||||
-rw-r--r-- | lib/utils/fs.js | 1 | ||||
-rw-r--r-- | lib/utils/images.js | 5 | ||||
-rw-r--r-- | lib/utils/location.js | 31 |
4 files changed, 33 insertions, 6 deletions
diff --git a/lib/utils/command.js b/lib/utils/command.js index 4269d6c..c3e33c7 100644 --- a/lib/utils/command.js +++ b/lib/utils/command.js @@ -19,7 +19,7 @@ function spawn(command, args, options) { return Promise.reject(new Error('Command execution is not possible on this platform')); } - var d = Promise.deferred(); + var d = Promise.defer(); var child = childProcess.spawn(command, args, options); child.on('error', function(error) { diff --git a/lib/utils/fs.js b/lib/utils/fs.js index 7745448..ea9546b 100644 --- a/lib/utils/fs.js +++ b/lib/utils/fs.js @@ -61,6 +61,7 @@ function genTmpFile(opts) { module.exports = { exists: fileExists, + existsSync: fs.existsSync, mkdirp: Promise.nfbind(mkdirp), readFile: Promise.nfbind(fs.readFile), writeFile: Promise.nfbind(fs.writeFile), diff --git a/lib/utils/images.js b/lib/utils/images.js index 45bc0b0..8169b06 100644 --- a/lib/utils/images.js +++ b/lib/utils/images.js @@ -1,5 +1,3 @@ -var fs = require('fs'); - var Promise = require('./promise'); var command = require('./command'); var fs = require('./fs'); @@ -38,6 +36,5 @@ function convertSVGBufferToPNG(buf, dest) { module.exports = { convertSVGToPNG: convertSVGToPNG, - convertSVGBufferToPNG: convertSVGBufferToPNG, - INVALID: ['.svg'] + convertSVGBufferToPNG: convertSVGBufferToPNG };
\ No newline at end of file diff --git a/lib/utils/location.js b/lib/utils/location.js index efe1425..3f3cb37 100644 --- a/lib/utils/location.js +++ b/lib/utils/location.js @@ -1,4 +1,5 @@ var url = require('url'); +var path = require('path'); // Is the url an external url function isExternal(href) { @@ -24,8 +25,36 @@ function isAnchor(href) { } } +// Normalize a path to be a link +function normalize(s) { + return s.replace(/\\/g, '/'); +} + +// Convert relative to absolute path +// dir: directory parent of the file currently in rendering process +// outdir: directory parent from the html output +function toAbsolute(_href, dir, outdir) { + outdir = outdir == undefined? dir : outdir; + + if (isExternal(_href)) return _href; + + // Path "_href" inside the base folder + var hrefInRoot = path.normalize(path.join(dir, _href)); + if (_href[0] == '/') hrefInRoot = path.normalize(_href.slice(1)); + + // Make it relative to output + _href = path.relative(outdir, hrefInRoot); + + // Normalize windows paths + _href = normalize(_href); + + return _href; +} + module.exports = { isExternal: isExternal, isRelative: isRelative, - isAnchor: isAnchor + isAnchor: isAnchor, + normalize: normalize, + toAbsolute: toAbsolute }; |