summaryrefslogtreecommitdiffstats
path: root/lib/generate/site/index.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-09-17 13:00:28 +0200
committerSamy Pessé <samypesse@gmail.com>2014-09-17 13:00:28 +0200
commitc8c07fe8ce7ccc3b4a83412025123cc05853dc40 (patch)
tree96e167b96d43d259cbdc6723fd6fafac84920db7 /lib/generate/site/index.js
parent9dc19026c6c849ee545204b5aecd84b22e7e8d84 (diff)
downloadgitbook-c8c07fe8ce7ccc3b4a83412025123cc05853dc40.zip
gitbook-c8c07fe8ce7ccc3b4a83412025123cc05853dc40.tar.gz
gitbook-c8c07fe8ce7ccc3b4a83412025123cc05853dc40.tar.bz2
Add base to use plugins in page format
Diffstat (limited to 'lib/generate/site/index.js')
-rw-r--r--lib/generate/site/index.js49
1 files changed, 33 insertions, 16 deletions
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js
index 0bd2318..5d3a57b 100644
--- a/lib/generate/site/index.js
+++ b/lib/generate/site/index.js
@@ -18,6 +18,9 @@ var Generator = function() {
// Attach methods to instance
_.bindAll(this);
+ // Base for assets in plugins
+ this.pluginAssetsBase = "book";
+
this.revision = Date.now();
this.indexer = indexer();
};
@@ -95,20 +98,15 @@ Generator.prototype.indexPage = function(lexed, pagePath) {
return Q();
};
-// Convert a markdown file to html
-Generator.prototype.convertFile = function(content, _input) {
+// Convert a markdown file into a normalized data set
+Generator.prototype.prepareFile = function(content, _input) {
var that = this;
- _output = _input.replace(".md", ".html");
- if (_output == "README.html") _output = "index.html";
-
var input = path.join(this.options.input, _input);
- var output = path.join(this.options.output, _output);
- var basePath = path.relative(path.dirname(output), this.options.output) || ".";
var page = {
path: _input,
- rawPath: input, // path to raw md file
+ rawPath: input,
content: content,
progress: parse.progress(this.options.navigation, _input)
};
@@ -131,11 +129,8 @@ Generator.prototype.convertFile = function(content, _input) {
return parse.lex(page.content);
})
.then(function(lexed) {
- // Index page in search
- return that.indexPage(lexed, _output)
- .then(_.constant(lexed));
- })
- .then(function(lexed) {
+ page.lexed = lexed;
+
// Get HTML generated sections
return parse.page(lexed, {
repo: that.options.githubId,
@@ -150,10 +145,30 @@ Generator.prototype.convertFile = function(content, _input) {
return _callHook("page");
})
.then(function() {
+ return page;
+ });
+};
+
+// Convert a markdown file to html
+Generator.prototype.convertFile = function(content, _input) {
+ var that = this;
+
+ var _output = _input.replace(".md", ".html");
+ if (_output == "README.html") _output = "index.html";
+ var output = path.join(this.options.output, _output);
+ var basePath = path.relative(path.dirname(output), this.options.output) || ".";
+
+ return this.prepareFile(content, _input)
+ .then(function(page) {
+ // Index page in search
+ return that.indexPage(page.lexed, _output).thenResolve(page);
+ })
+ .then(function(page) {
+ // Write file
return that._writeTemplate(that.template, {
progress: page.progress,
- _input: _input,
+ _input: page.path,
content: page.sections,
basePath: basePath,
@@ -161,7 +176,7 @@ Generator.prototype.convertFile = function(content, _input) {
}, output, function(html) {
page.content = html;
- return _callHook("page:after").get("content")
+ return that.callHook("page:after", page).get("content")
});
});
};
@@ -238,7 +253,9 @@ Generator.prototype.copyAssets = function() {
return Q.all(
_.map(that.plugins.list, function(plugin) {
var pluginAssets = path.join(that.options.output, "gitbook/plugins/", plugin.name);
- return plugin.copyAssets(pluginAssets);
+ return plugin.copyAssets(pluginAssets, {
+ base: this.pluginAssetsBase
+ });
})
);
});