diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/output/assets-inliner.js | 13 | ||||
-rw-r--r-- | lib/page/index.js | 8 | ||||
-rw-r--r-- | lib/utils/location.js | 8 |
3 files changed, 26 insertions, 3 deletions
diff --git a/lib/output/assets-inliner.js b/lib/output/assets-inliner.js index 5f33956..65ecbfa 100644 --- a/lib/output/assets-inliner.js +++ b/lib/output/assets-inliner.js @@ -22,8 +22,13 @@ AssetsInliner.prototype.onOutputSVG = function(page, svg) { this.log.debug.ln('output svg from', page.path); var filename = _.uniqueId('svg_') + '.png'; + // Convert svg buffer to a png file return imagesUtil.convertSVGBufferToPNG(svg, this.resolve(filename)) - .thenResolve('/' + filename); + + // Return relative path from the page + .thenResolve(function() { + return page.relative('/' + filename); + }); }; // Output an image as a file @@ -35,7 +40,11 @@ AssetsInliner.prototype.onOutputImage = function(page, imgFile) { // Convert SVG to PNG var filename = _.uniqueId('svg_') + '.png'; return imagesUtil.convertSVGToPNG(page.resolve(imgFile), this.resolve(filename)) - .thenResolve('/' + filename); + + // Return relative path from the page + .thenResolve(function() { + return page.relative('/' + filename); + }); }; diff --git a/lib/page/index.js b/lib/page/index.js index e96f89b..77b9950 100644 --- a/lib/page/index.js +++ b/lib/page/index.js @@ -78,6 +78,14 @@ Page.prototype.resolve = function() { return this.book.resolve(this.resolveLocal.apply(this, arguments)); }; +// Convert an absolite path to a relative path from this page +Page.prototype.relative = function(name) { + return location.relative( + this.resolve('.'), + this.resolve(name) + ); +}; + // Update content of the page Page.prototype.update = function(content) { this.content = content; diff --git a/lib/utils/location.js b/lib/utils/location.js index 3f3cb37..09fa93a 100644 --- a/lib/utils/location.js +++ b/lib/utils/location.js @@ -51,10 +51,16 @@ function toAbsolute(_href, dir, outdir) { return _href; } +// Convert an absolute path to a relative patg +function relative(dir, file) { + return normalize(path.relative(dir, file)); +} + module.exports = { isExternal: isExternal, isRelative: isRelative, isAnchor: isAnchor, normalize: normalize, - toAbsolute: toAbsolute + toAbsolute: toAbsolute, + relative: relative }; |