diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-29 17:45:52 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-29 17:45:54 +0200 |
commit | b3e5b3d1069897538aef1dfc57dd4a59f7cbed1a (patch) | |
tree | 036de821fb03f5053a3eb79907fbc19e48082ad1 /lib/generate/site/index.js | |
parent | b830ef5dca05c56513d835d006389fb72384f210 (diff) | |
download | gitbook-b3e5b3d1069897538aef1dfc57dd4a59f7cbed1a.zip gitbook-b3e5b3d1069897538aef1dfc57dd4a59f7cbed1a.tar.gz gitbook-b3e5b3d1069897538aef1dfc57dd4a59f7cbed1a.tar.bz2 |
Fix #183: normalize hooks and transformation of page (content, progress, ..°
Diffstat (limited to 'lib/generate/site/index.js')
-rw-r--r-- | lib/generate/site/index.js | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js index 87be7b4..e0ae1e4 100644 --- a/lib/generate/site/index.js +++ b/lib/generate/site/index.js @@ -100,7 +100,6 @@ Generator.prototype.indexPage = function(lexed, pagePath) { // Convert a markdown file to html Generator.prototype.convertFile = function(content, _input) { var that = this; - var progress = parse.progress(this.options.navigation, _input); _output = _input.replace(".md", ".html"); if (_output == "README.html") _output = "index.html"; @@ -109,19 +108,28 @@ Generator.prototype.convertFile = function(content, _input) { var output = path.join(this.options.output, _output); var basePath = path.relative(path.dirname(output), this.options.output) || "."; + var page = { + path: _input, + content: content, + progress: parse.progress(this.options.navigation, _input) + }; + + var _callHook = function(name) { + return that.callHook("page:before", page) + .then(function(_page) { + page = _page; + return page; + }); + }; + return Q() .then(function() { // Send content to plugins - return that.callHook("page:before", { - path: _input, - content: content - }); + return _callHook("page:before"); }) - .then(function(_content) { - content = _content.content; - + .then(function() { // Lex page - return parse.lex(content); + return parse.lex(page.content); }) .then(function(lexed) { // Index page in search @@ -137,28 +145,26 @@ Generator.prototype.convertFile = function(content, _input) { }); }) .then(function(sections) { + page.sections = sections; + // Use plugin hook - return that.callHook("page", { - path: _input, - sections: sections - }) + return _callHook("page"); }) - .then(function(_page) { + .then(function() { that.manifest.add("CACHE", _output); return that._writeTemplate(that.template, { - progress: _page.progress, + progress: page.progress, _input: _input, - content: _page.sections, + content: page.sections, basePath: basePath, staticBase: path.join(basePath, "gitbook"), }, output, function(html) { - return that.callHook("page:after", { - path: _input, - content: html - }).get("content") + page.content = html; + + return _callHook("page:after").get("content") }); }); }; |