blob: 5ba2d16767be032bcf45ae4013967dc01d95a953 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
var util = require('util');
var Generator = require('./base');
var gitbook = require('../gitbook');
function JSONGenerator() {
Generator.apply(this, arguments);
}
util.inherits(JSONGenerator, Generator);
// Write a page (parsable file)
JSONGenerator.prototype.writePage = function(page) {
var that = this;
// Parse the page
return page.parse()
// Write as json
.then(function() {
var json = {
gitbook: {
version: gitbook.version
},
path: page.path,
sections: page.content
};
return that.output.writeFile(
page.withExtension('.json'),
JSON.stringify(json, null, 4)
);
});
};
// 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;
|