mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Add filter resolveAsset to template for website
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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),
|
||||
|
||||
|
||||
+1
-5
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user