From b3e5b3d1069897538aef1dfc57dd4a59f7cbed1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 29 Apr 2014 17:45:52 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20#183:=20normalize=20hooks=20and=20transfo?= =?UTF-8?q?rmation=20of=20page=20(content,=20progress,=20..=C2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/generate/site/index.js | 46 +++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js index 87be7b439..e0ae1e4a0 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") }); }); };