diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-05-23 16:35:34 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-05-23 16:35:34 +0200 |
commit | bf21633b6c0f08f69452ceccf5e3c80dcbd62ad4 (patch) | |
tree | 63b6f2d1632a27d4763250031553f0c425ff0140 /lib/generate/json | |
parent | ad9b1fd6f7de7dd81dd5ad015b975014106ac945 (diff) | |
download | gitbook-bf21633b6c0f08f69452ceccf5e3c80dcbd62ad4.zip gitbook-bf21633b6c0f08f69452ceccf5e3c80dcbd62ad4.tar.gz gitbook-bf21633b6c0f08f69452ceccf5e3c80dcbd62ad4.tar.bz2 |
Support multi-languages book in json format
Diffstat (limited to 'lib/generate/json')
-rw-r--r-- | lib/generate/json/index.js | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/generate/json/index.js b/lib/generate/json/index.js index 9e61532..745933b 100644 --- a/lib/generate/json/index.js +++ b/lib/generate/json/index.js @@ -1,6 +1,7 @@ var util = require("util"); var path = require("path"); var Q = require("q"); +var _ = require("lodash"); var fs = require("../fs"); var parse = require("../../parse"); @@ -41,17 +42,29 @@ Generator.prototype.convertFile = function(content, input) { }; // Generate languages index +// Contains the first languages readme and langs infos Generator.prototype.langsIndex = function(langs) { var that = this; - var json = { - langs: langs.list - }; + if (langs.list.length == 0) return Q.reject("Need at least one language"); + + var mainLang = _.first(langs.list).lang; + console.log("Main language is", mainLang); return Q() .then(function() { + return fs.readFile( + path.join(that.options.output, mainLang, "README.json") + ); + }) + .then(function(content) { + var json = JSON.parse(content); + _.extend(json, { + langs: langs.list + }); + return fs.writeFile( - path.join(that.options.output, "langs.json"), + path.join(that.options.output, "README.json"), JSON.stringify(json, null, 4) ); }); |