Fix #183: normalize hooks and transformation of page (content, progress, ..°

This commit is contained in:
Samy Pessé
2014-04-29 17:45:52 +02:00
parent b830ef5dca
commit b3e5b3d106
+26 -20
View File
@@ -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")
});
});
};