summaryrefslogtreecommitdiffstats
path: root/lib/output/json.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-26 09:41:26 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-26 09:41:26 +0100
commitd3d64f636c859f7f01a64f7774cf70bd8ccdc562 (patch)
tree4f7731f37c3a793d187b0ab1cd77680e69534c6c /lib/output/json.js
parent4cb9cbb5ae3aa8f9211ffa3ac5e3d34232c0ca4f (diff)
parenteef072693b17526347c37b66078a5059c71caa31 (diff)
downloadgitbook-d3d64f636c859f7f01a64f7774cf70bd8ccdc562.zip
gitbook-d3d64f636c859f7f01a64f7774cf70bd8ccdc562.tar.gz
gitbook-d3d64f636c859f7f01a64f7774cf70bd8ccdc562.tar.bz2
Merge pull request #1109 from GitbookIO/3.0.0
Version 3.0.0
Diffstat (limited to 'lib/output/json.js')
-rw-r--r--lib/output/json.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/output/json.js b/lib/output/json.js
new file mode 100644
index 0000000..e8a71cc
--- /dev/null
+++ b/lib/output/json.js
@@ -0,0 +1,47 @@
+var conrefsLoader = require('./conrefs');
+
+var JSONOutput = conrefsLoader();
+
+JSONOutput.prototype.name = 'json';
+
+// 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.toHTML(this)
+
+ // Write as json
+ .then(function() {
+ var json = page.getContext();
+
+ // Delete some private properties
+ delete json.config;
+
+ // Specify JSON output version
+ json.version = '2';
+
+ 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;