diff options
Diffstat (limited to 'lib/generate/site/index.js')
-rw-r--r-- | lib/generate/site/index.js | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js index f8986df..87be7b4 100644 --- a/lib/generate/site/index.js +++ b/lib/generate/site/index.js @@ -59,8 +59,11 @@ Generator.prototype.loadPlugins = function() { }; // Generate a template -Generator.prototype._writeTemplate = function(tpl, options, output) { +Generator.prototype._writeTemplate = function(tpl, options, output, interpolate) { var that = this; + + interpolate = interpolate || _.identity; + return Q() .then(function(sections) { return tpl(_.extend({ @@ -80,6 +83,7 @@ Generator.prototype._writeTemplate = function(tpl, options, output) { pluginsConfig: JSON.stringify(that.options.pluginsConfig) }, options)); }) + .then(interpolate) .then(function(html) { return fs.writeFile( output, @@ -107,6 +111,15 @@ Generator.prototype.convertFile = function(content, _input) { return Q() .then(function() { + // Send content to plugins + return that.callHook("page:before", { + path: _input, + content: content + }); + }) + .then(function(_content) { + content = _content.content; + // Lex page return parse.lex(content); }) @@ -124,17 +137,29 @@ Generator.prototype.convertFile = function(content, _input) { }); }) .then(function(sections) { + // Use plugin hook + return that.callHook("page", { + path: _input, + sections: sections + }) + }) + .then(function(_page) { that.manifest.add("CACHE", _output); return that._writeTemplate(that.template, { - progress: progress, + progress: _page.progress, _input: _input, - content: sections, + content: _page.sections, basePath: basePath, staticBase: path.join(basePath, "gitbook"), - }, output); + }, output, function(html) { + return that.callHook("page:after", { + path: _input, + content: html + }).get("content") + }); }); }; |