summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-04-28 19:56:40 +0200
committerSamy Pessé <samypesse@gmail.com>2014-04-28 19:56:40 +0200
commitb715901f9203daacf705ce4e9db47b3d75980996 (patch)
tree49e8ab637d89d7c7f096206ad4a239b06b691b0e
parent38fea06cf96360a08a0b704715436d6136797cb6 (diff)
downloadgitbook-b715901f9203daacf705ce4e9db47b3d75980996.zip
gitbook-b715901f9203daacf705ce4e9db47b3d75980996.tar.gz
gitbook-b715901f9203daacf705ce4e9db47b3d75980996.tar.bz2
Add hooks "page:before" and "page:after"
-rw-r--r--lib/generate/site/index.js26
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js
index f0ed784..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);
})
@@ -126,8 +139,8 @@ Generator.prototype.convertFile = function(content, _input) {
.then(function(sections) {
// Use plugin hook
return that.callHook("page", {
- sections: sections,
- progress: progress
+ path: _input,
+ sections: sections
})
})
.then(function(_page) {
@@ -141,7 +154,12 @@ Generator.prototype.convertFile = function(content, _input) {
basePath: basePath,
staticBase: path.join(basePath, "gitbook"),
- }, output);
+ }, output, function(html) {
+ return that.callHook("page:after", {
+ path: _input,
+ content: html
+ }).get("content")
+ });
});
};