Skip to content

Commit 9630dbf

Browse files
committed
Merge branch 'master' of github.com:GitbookIO/gitbook
Conflicts: theme/assets/print.css theme/assets/style.css
2 parents 6ba02f1 + 1e46320 commit 9630dbf

File tree

25 files changed

+114
-52
lines changed

25 files changed

+114
-52
lines changed

CHANGES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Release notes
22

3+
## 1.2.0
4+
- Improvements on ebook generation
5+
- Fix incorrect follow of links in ebook generation
6+
- Move Table of Contents at the beginning of the ebook
7+
- Update to last highlight.js (includes Swift)
8+
- Includes of templates and variables (from book.json)
9+
310
## 1.1.1
411
- Rewrite quiz logic to be more robust
512
- Improve integration of glossary

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ Here are the options that can be stored in this file:
111111
}
112112
},
113113
114+
// Variables for templating
115+
"variables": {},
116+
114117
// Links in template (null: default, false: remove, string: new value)
115118
"links": {
116119
// Custom links at top of sidebar
@@ -133,9 +136,6 @@ Here are the options that can be stored in this file:
133136
134137
// Options for PDF generation
135138
"pdf": {
136-
// Add toc at the end of the file
137-
"toc": true,
138-
139139
// Add page numbers to the bottom of every page
140140
"pageNumbers": false,
141141
@@ -248,7 +248,7 @@ The platform [GitBook.io](https://www.gitbook.io/) is like an "Heroku for books"
248248

249249
#### Plugins
250250

251-
Plugins can used to extend your book's functionality. Read [GitbookIO/plugin](https://github.com/GitbookIO/plugin) for more information about how to build a plugin for GitBook.
251+
Plugins can be used to extend your book's functionality. Read [GitbookIO/plugin](https://github.com/GitbookIO/plugin) for more information about how to build a plugin for GitBook.
252252

253253
##### Official plugins:
254254

@@ -258,6 +258,7 @@ Plugins can used to extend your book's functionality. Read [GitbookIO/plugin](ht
258258
| [quizzes](https://github.com/GitbookIO/plugin-quizzes) | Add interactive quizzes to your book. |
259259
| [mathjax](https://github.com/GitbookIO/plugin-mathjax) | Displays mathematical notation in the book. |
260260
| [mixpanel](https://github.com/GitbookIO/plugin-mixpanel) | Mixpanel tracking for your book |
261+
| [infinitescroll](https://github.com/GitbookIO/gitbook-plugin-infinitescroll) | Infinite Scrolling |
261262

262263
##### Other plugins:
263264

lib/generate/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ var CONFIG = {
3838
}
3939
},
4040

41+
// Variables for templating
42+
"variables": {},
43+
4144
// Set another theme with your own layout
4245
// It's recommended to use plugins or add more options for default theme, though
4346
// See https://github.com/GitbookIO/gitbook/issues/209

lib/generate/ebook/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Generator.prototype.finish = function() {
3939
"--level2-toc": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-2 ')]",
4040
"--level3-toc": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-3 ')]",
4141
"--no-chapters-in-toc": true,
42-
"--max-levels": "1000"
42+
"--max-levels": "1",
43+
"--breadth-first": true
4344
};
4445

4546
if (format == "pdf") {
@@ -50,7 +51,6 @@ Generator.prototype.finish = function() {
5051
"--margin-right": String(pdfOptions.margin.right),
5152
"--margin-top": String(pdfOptions.margin.top),
5253
"--margin-bottom": String(pdfOptions.margin.bottom),
53-
"--pdf-add-toc": Boolean(pdfOptions.toc),
5454
"--pdf-default-font-size": String(pdfOptions.fontSize),
5555
"--pdf-mono-font-size": String(pdfOptions.fontSize),
5656
"--paper-size": String(pdfOptions.paperSize),
@@ -62,7 +62,7 @@ Generator.prototype.finish = function() {
6262

6363
var command = [
6464
"ebook-convert",
65-
path.join(that.options.output, "index.html"),
65+
path.join(that.options.output, "SUMMARY.html"),
6666
path.join(that.options.output, "index."+format),
6767
stringUtils.optionsToShellArgs(_options)
6868
].join(" ");

lib/generate/generator.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ var BaseGenerator = function(options) {
1414
this.options.plugins = Plugin.normalizeNames(this.options.plugins);
1515
this.options.plugins = _.union(this.options.plugins, this.options.defaultsPlugins);
1616
this.plugins = [];
17-
18-
// Include variables (not yet loaded)
19-
this.variables = {};
2017
};
2118

2219
BaseGenerator.prototype.callHook = function(name, data) {
@@ -25,22 +22,7 @@ BaseGenerator.prototype.callHook = function(name, data) {
2522

2623
// Sets up generator
2724
BaseGenerator.prototype.load = function() {
28-
return this.loadVariables()
29-
.then(this.loadPlugins.bind(this));
30-
};
31-
32-
BaseGenerator.prototype.loadVariables = function() {
33-
var that = this;
34-
35-
return fs.readFile(path.join(this.options.input, 'variables.json'), 'utf8')
36-
.then(function(content) {
37-
try {
38-
that.variables = JSON.parse(content);
39-
} catch(err) {
40-
console.log('No variables.json');
41-
}
42-
})
43-
.fail(function() {});
25+
return this.loadPlugins();
4426
};
4527

4628
BaseGenerator.prototype.loadPlugins = function() {

lib/generate/page/index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,25 @@ util.inherits(Generator, BaseGenerator);
2121

2222
Generator.prototype.loadTemplates = function() {
2323
this.template = swig.compileFile(
24-
this.plugins.template("page") || path.resolve(this.options.theme, 'templates/page.html')
24+
this.plugins.template("ebook:page") || path.resolve(this.options.theme, 'templates/ebook/page.html')
25+
);
26+
this.summaryTemplate = swig.compileFile(
27+
this.plugins.template("ebook:sumary") || path.resolve(this.options.theme, 'templates/ebook/summary.html')
2528
);
2629
};
2730

31+
// Generate table of contents
32+
Generator.prototype.writeToc = function() {
33+
var that = this;
34+
var basePath = ".";
35+
36+
return this._writeTemplate(this.summaryTemplate, {
37+
toc: parse.progress(this.options.navigation, "README.md").chapters,
38+
basePath: basePath,
39+
staticBase: path.join(basePath, "gitbook"),
40+
}, path.join(this.options.output, "SUMMARY.html"));
41+
};
42+
2843
Generator.prototype.finish = function() {
2944
var that = this;
3045
var basePath = ".";
@@ -34,6 +49,11 @@ Generator.prototype.finish = function() {
3449

3550
return Q()
3651

52+
// Write table of contents
53+
.then(function() {
54+
return that.writeToc();
55+
})
56+
3757
// Copy cover
3858
.then(function() {
3959
return that.copyCover();

lib/generate/site/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ Generator.prototype.load = function() {
3636
// Load all templates
3737
Generator.prototype.loadTemplates = function() {
3838
this.template = swig.compileFile(
39-
this.plugins.template("site") || path.resolve(this.options.theme, 'templates/site.html')
39+
this.plugins.template("site:page") || path.resolve(this.options.theme, 'templates/book/page.html')
4040
);
4141
this.langsTemplate = swig.compileFile(
42-
this.plugins.template("langs") || path.resolve(this.options.theme, 'templates/langs.html')
42+
this.plugins.template("site:langs") || path.resolve(this.options.theme, 'templates/book/langs.html')
4343
);
4444
this.glossaryTemplate = swig.compileFile(
45-
this.plugins.template("glossary") || path.resolve(this.options.theme, 'templates/glossary.html')
45+
this.plugins.template("site:glossary") || path.resolve(this.options.theme, 'templates/book/glossary.html')
4646
);
4747
};
4848

@@ -128,7 +128,7 @@ Generator.prototype.prepareFile = function(content, _input) {
128128
// Output directory
129129
outdir: path.dirname(_input) || '/',
130130
// Templating variables
131-
variables: that.variables,
131+
variables: that.options.variables,
132132
});
133133
})
134134
.then(function(sections) {

lib/utils/string.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ function escapeShellArg(arg) {
1111
function optionsToShellArgs(options) {
1212
return _.chain(options)
1313
.map(function(value, key) {
14-
if (value == null || value == false) return null;
15-
if (value == true) return key;
14+
if (value == null || value === false) return null;
15+
if (value === true) return key;
1616
return key+"="+escapeShellArg(value);
1717
})
1818
.compact()

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gitbook",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"homepage": "http://www.gitbook.io/",
55
"description": "Library and cmd utility to generate GitBooks",
66
"main": "lib/index.js",
@@ -16,7 +16,7 @@
1616
"commander": "2.2.0",
1717
"graceful-fs": "3.0.2",
1818
"fs-extra": "0.10.0",
19-
"highlight.js": "8.2.0",
19+
"highlight.js": "8.3.0",
2020
"tmp": "0.0.23",
2121
"semver": "2.2.1",
2222
"gaze": "~0.5.1",

0 commit comments

Comments
 (0)