mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-18 08:35:10 +00:00
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
var util = require('util');
|
|
var FolderOutput = require('./folder');
|
|
var gitbook = require('../gitbook');
|
|
|
|
function JSONOutput() {
|
|
FolderOutput.apply(this, arguments);
|
|
}
|
|
util.inherits(JSONOutput, FolderOutput);
|
|
|
|
// Don't copy asset on JSON output
|
|
JSONOutput.prototype.onAsset = function(filename) {
|
|
|
|
};
|
|
|
|
// Write a page (parsable file)
|
|
JSONOutput.prototype.onPage = function(page) {
|
|
var that = this;
|
|
|
|
// Parse the page
|
|
return page.parse(this)
|
|
|
|
// Write as json
|
|
.then(function() {
|
|
var json = {
|
|
gitbook: {
|
|
version: gitbook.version
|
|
},
|
|
path: page.path,
|
|
sections: page.content
|
|
};
|
|
|
|
return that.writeFile(
|
|
page.withExtension('.json'),
|
|
JSON.stringify(json, null, 4)
|
|
);
|
|
});
|
|
};
|
|
|
|
// At the end of generation, generate README.json for multilingual books
|
|
JSONOutput.prototype.finish = function() {
|
|
if (!this.book.isMultilingual()) return;
|
|
|
|
// Copy README.json from main book
|
|
var mainLanguage = this.book.langs.getDefault().id;
|
|
return this.copyFile(
|
|
this.resolve(mainLanguage, 'README.json'),
|
|
'README.json'
|
|
);
|
|
};
|
|
|
|
|
|
module.exports = JSONOutput;
|