diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-18 10:04:23 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-18 10:04:23 +0100 |
commit | b66242db985fd8d6088b52d4b089f0de2ecb8058 (patch) | |
tree | e11467b9ada96d5fdd510b2d3a08ceae8b575329 | |
parent | 004ac8851622cb4583b5569ae3480344855a7880 (diff) | |
download | gitbook-b66242db985fd8d6088b52d4b089f0de2ecb8058.zip gitbook-b66242db985fd8d6088b52d4b089f0de2ecb8058.tar.gz gitbook-b66242db985fd8d6088b52d4b089f0de2ecb8058.tar.bz2 |
Add filter resolveAsset to template for website
-rw-r--r-- | lib/output/assets-inliner.js | 2 | ||||
-rw-r--r-- | lib/output/base.js | 8 | ||||
-rw-r--r-- | lib/output/folder.js | 5 | ||||
-rw-r--r-- | lib/output/website.js | 11 | ||||
-rw-r--r-- | lib/page/index.js | 1 | ||||
-rw-r--r-- | package.json | 6 |
6 files changed, 22 insertions, 11 deletions
diff --git a/lib/output/assets-inliner.js b/lib/output/assets-inliner.js index b5d076e..8d7c48e 100644 --- a/lib/output/assets-inliner.js +++ b/lib/output/assets-inliner.js @@ -68,7 +68,7 @@ module.exports = function assetsInliner(Base) { } // Convert SVG to PNG - return that.convertSVGFile(that.resolveForPage(page, src)); + return that.convertSVGFile(that.resolveOutputForPage(page, src)); }) // Return relative path from the page diff --git a/lib/output/base.js b/lib/output/base.js index 7b527da..e674f46 100644 --- a/lib/output/base.js +++ b/lib/output/base.js @@ -173,6 +173,14 @@ Output.prototype.getPageContext = function(page) { ); }; +// Resolve a file path in the context of a specific page +// Result is an "absolute path relative to the output folder" +Output.prototype.resolveForPage = function(page, href) { + if (_.isString(page)) page = this.book.getPage(page); + + href = page.relative(href); + return this.onRelativeLink(page, href); +}; // Filename for output // READMEs are replaced by index.html diff --git a/lib/output/folder.js b/lib/output/folder.js index 5a51346..14e3f22 100644 --- a/lib/output/folder.js +++ b/lib/output/folder.js @@ -72,7 +72,10 @@ module.exports = function folderOutput(Base) { }; // Resolve a file path from a page (in the output folder) - FolderOutput.prototype.resolveForPage = function(page, filename) { + // Result is an absolute path (enforced in outptu folder) + FolderOutput.prototype.resolveOutputForPage = function(page, filename) { + if (_.isString(page)) page = this.book.getPage(page); + var abs = page.resolveLocal(filename); return this.resolve(abs); }; diff --git a/lib/output/website.js b/lib/output/website.js index a208802..f58c68f 100644 --- a/lib/output/website.js +++ b/lib/output/website.js @@ -77,15 +77,20 @@ WebsiteOutput.prototype.prepare = function() { // Transform an absolute path into a relative path // using this.ctx.page.path - that.env.addFilter('resolveFile', function(s) { - // todo - return s; + that.env.addFilter('resolveFile', function(href) { + return that.resolveForPage(this.ctx.file.path, href); }); // Transform a '.md' into a '.html' (README -> index) that.env.addFilter('contentURL', function(s) { return that.onRelativeLink(null, s); }); + + // Relase path to an asset + that.env.addFilter('resolveAsset', function(href) { + href = path.join('/gitbook', href); + return that.resolveForPage(this.ctx.file.path, href); + }); }); }; diff --git a/lib/page/index.js b/lib/page/index.js index 629bcee..c92bdfa 100644 --- a/lib/page/index.js +++ b/lib/page/index.js @@ -151,7 +151,6 @@ Page.prototype.toHTML = function(output) { href = that.relative(href); return output.onRelativeLink(that, href); }, - //_.partial(output.onRelativeLink, that), onImage: _.partial(output.onOutputImage, that), onOutputSVG: _.partial(output.onOutputSVG, that), diff --git a/package.json b/package.json index 8ef7d00..03bc3d1 100644 --- a/package.json +++ b/package.json @@ -59,11 +59,7 @@ "gulp-util": "3.0.6", "browserify": "11.0.1", "merge-stream": "0.1.7", - "vinyl-source-stream": "1.1.0", - "jquery": "2.1.4", - "mousetrap": "1.5.3", - "font-awesome": "4.1.0", - "gitbook-markdown-css": "1.0.1" + "vinyl-source-stream": "1.1.0" }, "scripts": { "test": "node_modules/.bin/mocha --reporter spec --bail --timeout 15000 ./test/all.js" |