summaryrefslogtreecommitdiffstats
path: root/lib/generators/json.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/generators/json.js')
-rw-r--r--lib/generators/json.js19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/generators/json.js b/lib/generators/json.js
index 0cfaeb7..560f099 100644
--- a/lib/generators/json.js
+++ b/lib/generators/json.js
@@ -1,5 +1,6 @@
var util = require('util');
var Generator = require('./base');
+var gitbook = require('../gitbook');
function JSONGenerator() {
Generator.apply(this, arguments);
@@ -15,7 +16,13 @@ JSONGenerator.prototype.writePage = function(page) {
// Write as json
.then(function() {
- var json = {};
+ var json = {
+ gitbook: {
+ version: gitbook.version
+ },
+ path: page.path,
+ sections: page.content.sections
+ };
return that.output.writeFile(
page.withExtension('.json'),
@@ -24,7 +31,17 @@ JSONGenerator.prototype.writePage = function(page) {
});
};
+// At the end of generation, generate README.json for multilingual books
+JSONGenerator.prototype.finish = function() {
+ if (!this.book.isMultilingual()) return;
+ // Copy README.json from main book
+ var mainLanguage = this.book.langs.getDefault().id;
+ return this.output.copyFile(
+ this.output.resolve(mainLanguage, 'README.json'),
+ 'README.json'
+ );
+};
module.exports = JSONGenerator;