summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/generate/ebook/index.js6
-rw-r--r--lib/generate/page/index.js22
-rw-r--r--lib/utils/string.js4
3 files changed, 26 insertions, 6 deletions
diff --git a/lib/generate/ebook/index.js b/lib/generate/ebook/index.js
index 0acbbc6..bc39e15 100644
--- a/lib/generate/ebook/index.js
+++ b/lib/generate/ebook/index.js
@@ -39,7 +39,8 @@ Generator.prototype.finish = function() {
"--level2-toc": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-2 ')]",
"--level3-toc": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-3 ')]",
"--no-chapters-in-toc": true,
- "--max-levels": "1000"
+ "--max-levels": "1",
+ "--breadth-first": true
};
if (format == "pdf") {
@@ -50,7 +51,6 @@ Generator.prototype.finish = function() {
"--margin-right": String(pdfOptions.margin.right),
"--margin-top": String(pdfOptions.margin.top),
"--margin-bottom": String(pdfOptions.margin.bottom),
- "--pdf-add-toc": Boolean(pdfOptions.toc),
"--pdf-default-font-size": String(pdfOptions.fontSize),
"--pdf-mono-font-size": String(pdfOptions.fontSize),
"--paper-size": String(pdfOptions.paperSize),
@@ -62,7 +62,7 @@ Generator.prototype.finish = function() {
var command = [
"ebook-convert",
- path.join(that.options.output, "index.html"),
+ path.join(that.options.output, "SUMMARY.html"),
path.join(that.options.output, "index."+format),
stringUtils.optionsToShellArgs(_options)
].join(" ");
diff --git a/lib/generate/page/index.js b/lib/generate/page/index.js
index fb7c59d..068358c 100644
--- a/lib/generate/page/index.js
+++ b/lib/generate/page/index.js
@@ -21,10 +21,25 @@ util.inherits(Generator, BaseGenerator);
Generator.prototype.loadTemplates = function() {
this.template = swig.compileFile(
- this.plugins.template("page") || path.resolve(this.options.theme, 'templates/page.html')
+ this.plugins.template("page") || path.resolve(this.options.theme, 'templates/page/page.html')
+ );
+ this.summaryTemplate = swig.compileFile(
+ this.plugins.template("page/sumary") || path.resolve(this.options.theme, 'templates/page/summary.html')
);
};
+// Generate table of contents
+Generator.prototype.writeToc = function() {
+ var that = this;
+ var basePath = ".";
+
+ return this._writeTemplate(this.summaryTemplate, {
+ toc: parse.progress(this.options.navigation, "README.md").chapters,
+ basePath: basePath,
+ staticBase: path.join(basePath, "gitbook"),
+ }, path.join(this.options.output, "SUMMARY.html"));
+};
+
Generator.prototype.finish = function() {
var that = this;
var basePath = ".";
@@ -34,6 +49,11 @@ Generator.prototype.finish = function() {
return Q()
+ // Write table of contents
+ .then(function() {
+ return that.writeToc();
+ })
+
// Copy cover
.then(function() {
return that.copyCover();
diff --git a/lib/utils/string.js b/lib/utils/string.js
index 417d7af..54c4c66 100644
--- a/lib/utils/string.js
+++ b/lib/utils/string.js
@@ -11,8 +11,8 @@ function escapeShellArg(arg) {
function optionsToShellArgs(options) {
return _.chain(options)
.map(function(value, key) {
- if (value == null || value == false) return null;
- if (value == true) return key;
+ if (value == null || value === false) return null;
+ if (value === true) return key;
return key+"="+escapeShellArg(value);
})
.compact()