Skip to content

Commit 77c5259

Browse files
committed
Merge branch 'master' of github.com:GitbookIO/gitbook
Conflicts: theme/assets/app.js theme/assets/print.css
2 parents 6326e91 + ce50b89 commit 77c5259

File tree

29 files changed

+498
-300
lines changed

29 files changed

+498
-300
lines changed

CHANGES.md

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

3+
## 1.1.1
4+
- Rewrite quiz logic to be more robust
5+
- Improve integration of glossary
6+
- Improve generation of ebook by using a multiple HTML pages input source
7+
- Fix incorrect page breaks after h1 and h2 divs
8+
- New options to set header and footer in PDF generation
9+
10+
## 1.1.0
11+
- Plugins can now extend the ebook generation (pdf, epub, mobi)
12+
- Update `kramed` to version 0.4.3
13+
314
## 1.0.3
415
- Update `mathjax` plugin and MathJAx to version 2.4
516
- Update `highlight.js` to 8.2.0

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ Here are the options that can be stored in this file:
9595
// It's not advised this option in the book.json
9696
"extension": null,
9797
98-
// GitHub information (defaults are extracted using git)
99-
"github": null,
100-
"githubHost": "https://github.com/",
101-
10298
// Plugins list, can contain "-name" for removing default plugins
10399
"plugins": [],
104100
@@ -153,7 +149,13 @@ Here are the options that can be stored in this file:
153149
"left": 62,
154150
"top": 36,
155151
"bottom": 36
156-
}
152+
},
153+
154+
//Header HTML template. Available variables: _PAGENUM_, _TITLE_, _AUTHOR_ and _SECTION_.
155+
"headerTemplate": null,
156+
157+
//Footer HTML template. Available variables: _PAGENUM_, _TITLE_, _AUTHOR_ and _SECTION_.
158+
"footerTemplate": null
157159
}
158160
}
159161
```
@@ -166,7 +168,6 @@ GitBook can generate your book in the following formats:
166168

167169
* **Static Website**: This is the default format. It generates a complete interactive static website that can be, for example, hosted on GitHub Pages.
168170
* **eBook**: A complete eBook with exercise solutions at the end of the book. Generate this format using: ```gitbook ebook ./myrepo```. You need to have [ebook-convert](http://manual.calibre-ebook.com/cli/ebook-convert.html) installed. The output format could be **PDF**, **ePub** or **MOBI**.
169-
* **Single Page**: The book will be stored in a single printable HTML page. This format is used for conversion to PDF or eBook. Generate this format using: ```gitbook build ./myrepo -f page```.
170171
* **JSON**: This format is used for debugging or extracting metadata from a book. Generate this format using: ```gitbook build ./myrepo -f json```.
171172

172173
## Book Format
@@ -228,7 +229,7 @@ With it's definition, this can contain bold text and all other kinds of inline m
228229

229230
GitBook will read the `.gitignore`, `.bookignore` and `.ignore` files to get a list of files and folders to skip. (The format inside those files follows the same convention as `.gitignore`).
230231

231-
Best practices for the `.gitignore` is to ignore build files from [**node.js**](https://github.com/github/gitignore/blob/master/Node.gitignore) (`node_modules`, ...) and build files from GitBook: `_book`, `*.epub`, `*.mobi` and `*.pdf`.
232+
Best practices for the `.gitignore` is to ignore build files from **node.js** (`node_modules`, ...) and build files from GitBook: `_book`, `*.epub`, `*.mobi` and `*.pdf` ([Download GitBook.gitignore](https://github.com/github/gitignore/blob/master/GitBook.gitignore)).
232233

233234
#### Cover
234235

lib/generate/config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ var CONFIG = {
8383
"left": 62,
8484
"top": 36,
8585
"bottom": 36
86-
}
86+
},
87+
88+
//Header HTML template. Available variables: _PAGENUM_, _TITLE_, _AUTHOR_ and _SECTION_.
89+
"headerTemplate": "",
90+
91+
//Footer HTML template. Available variables: _PAGENUM_, _TITLE_, _AUTHOR_ and _SECTION_.
92+
"footerTemplate": ""
8793
}
8894
};
8995

lib/generate/ebook/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ var parse = require("../../parse");
99
var BaseGenerator = require("../page");
1010
var stringUtils = require("../../utils/string");
1111

12-
/*
13-
* This generator inherits from the single page generator
14-
* and convert the page output to ebook
15-
*/
1612
var Generator = function() {
1713
BaseGenerator.apply(this, arguments);
1814
};
@@ -35,12 +31,15 @@ Generator.prototype.finish = function() {
3531
"--title": that.options.title,
3632
"--comments": that.options.description,
3733
"--authors": that.options.author,
34+
"--publisher": "GitBook",
3835
"--chapter": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter ')]",
3936
"--chapter-mark": "pagebreak",
37+
"--page-breaks-before": "/",
4038
"--level1-toc": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-1 ')]",
4139
"--level2-toc": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-2 ')]",
4240
"--level3-toc": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-3 ')]",
43-
"--no-chapters-in-toc": true
41+
"--no-chapters-in-toc": true,
42+
"--max-levels": "1000"
4443
};
4544

4645
if (format == "pdf") {
@@ -55,7 +54,9 @@ Generator.prototype.finish = function() {
5554
"--pdf-default-font-size": String(pdfOptions.fontSize),
5655
"--pdf-mono-font-size": String(pdfOptions.fontSize),
5756
"--paper-size": String(pdfOptions.paperSize),
58-
"--pdf-page-numbers": Boolean(pdfOptions.pageNumbers)
57+
"--pdf-page-numbers": Boolean(pdfOptions.pageNumbers),
58+
"--pdf-header-template": String(pdfOptions.headerTemplate),
59+
"--pdf-footer-template": String(pdfOptions.footerTemplate)
5960
});
6061
}
6162

lib/generate/generator.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,35 @@ 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 = {};
1720
};
1821

1922
BaseGenerator.prototype.callHook = function(name, data) {
2023
return this.plugins.hook(name, data);
2124
};
2225

26+
// Sets up generator
27+
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() {});
44+
};
45+
2346
BaseGenerator.prototype.loadPlugins = function() {
2447
var that = this;
2548

@@ -79,6 +102,4 @@ BaseGenerator.prototype.finish = function() {
79102
return Q.reject(new Error("Could not finish generation"));
80103
};
81104

82-
83-
84-
module.exports = BaseGenerator;
105+
module.exports = BaseGenerator;

lib/generate/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var loadGenerator = function(options) {
4040
.then(function() {
4141
var generator = new generators[options.generator](options);
4242

43-
return generator.loadPlugins()
43+
return generator.load()
4444
.then(_.constant(generator));
4545
});
4646
};

lib/generate/json/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ Generator.prototype.finish = function() {
7373
// ignore
7474
};
7575

76-
module.exports = Generator;
76+
module.exports = Generator;

lib/generate/page/index.js

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ var fs = require("../fs");
88
var parse = require("../../parse");
99
var BaseGenerator = require("../site");
1010

11-
12-
/*
13-
* This generator will generate a simple index.html which can be converted as a PDF
14-
*/
1511
var Generator = function() {
1612
BaseGenerator.apply(this, arguments);
1713

@@ -23,31 +19,12 @@ var Generator = function() {
2319
};
2420
util.inherits(Generator, BaseGenerator);
2521

26-
// Load all templates
2722
Generator.prototype.loadTemplates = function() {
2823
this.template = swig.compileFile(
2924
this.plugins.template("page") || path.resolve(this.options.theme, 'templates/page.html')
3025
);
3126
};
3227

33-
Generator.prototype.convertFile = function(content, input) {
34-
var that = this;
35-
var json = {
36-
path: input,
37-
progress: parse.progress(this.options.navigation, input)
38-
};
39-
40-
return this.prepareFile(content, input)
41-
.then(function(page) {
42-
that.pages[input] = page;
43-
});
44-
};
45-
46-
// Generate languages index
47-
Generator.prototype.langsIndex = function(langs) {
48-
return Q();
49-
};
50-
5128
Generator.prototype.finish = function() {
5229
var that = this;
5330
var basePath = ".";
@@ -56,16 +33,6 @@ Generator.prototype.finish = function() {
5633
var progress = parse.progress(this.options.navigation, "README.md");
5734

5835
return Q()
59-
// Generate html
60-
.then(function(pages) {
61-
return that._writeTemplate(that.template, {
62-
pages: that.pages,
63-
progress: progress,
64-
65-
basePath: basePath,
66-
staticBase: path.join(basePath, "gitbook"),
67-
}, output);
68-
})
6936

7037
// Copy cover
7138
.then(function() {
@@ -78,4 +45,9 @@ Generator.prototype.finish = function() {
7845
});
7946
};
8047

81-
module.exports = Generator;
48+
// Generate languages index
49+
Generator.prototype.langsIndex = function(langs) {
50+
return Q();
51+
};
52+
53+
module.exports = Generator;

lib/generate/plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var resolve = require('resolve');
88

99
var pkg = require("../../package.json");
1010

11-
var RESOURCES = ["js", "css"];
11+
var RESOURCES = ["js", "css"];
1212

1313
var Plugin = function(name, root, generator) {
1414
this.name = name;

lib/generate/site/glossary_indexer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var _ = require("lodash");
2-
32
var kramed = require('kramed');
43
var textRenderer = require('kramed-text-renderer');
54

0 commit comments

Comments
 (0)