diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-19 20:46:05 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-19 20:46:05 +0100 |
commit | 9a2b03b1835ca14239b61fb7b8610c782bb460e7 (patch) | |
tree | c5e86316b690f7341fc652058e8c9b35ffa8176f | |
parent | 2b2b4f46c2102a85bbc98dc17fe27085d2035c40 (diff) | |
download | gitbook-9a2b03b1835ca14239b61fb7b8610c782bb460e7.zip gitbook-9a2b03b1835ca14239b61fb7b8610c782bb460e7.tar.gz gitbook-9a2b03b1835ca14239b61fb7b8610c782bb460e7.tar.bz2 |
Handle different structure in json multilingual output
-rw-r--r-- | lib/book.js | 4 | ||||
-rw-r--r-- | lib/generator.js | 5 | ||||
-rw-r--r-- | lib/generators/json.js | 5 |
3 files changed, 12 insertions, 2 deletions
diff --git a/lib/book.js b/lib/book.js index 19b5f43..b98c9f5 100644 --- a/lib/book.js +++ b/lib/book.js @@ -45,6 +45,9 @@ var Book = function(root, options, parent) { // List of plugins this.plugins = {}; + + // Readme file + this.readmeFile = "README.md"; }; // Initialize and parse the book: config, summary, glossary @@ -211,6 +214,7 @@ Book.prototype.parseReadme = function() { .then(function(readme) { if (!readme) throw "No README file"; + that.readmeFile = readme.path; return that.template.renderFile(readme.path) .then(function(content) { return readme.parser.readme(content); diff --git a/lib/generator.js b/lib/generator.js index fa6b8b0..58a9c79 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -83,4 +83,9 @@ BaseGenerator.prototype.finish = function() { return Q.reject(new Error("Could not finish generation")); }; +// Modify an extension from a path +BaseGenerator.prototype.changeExtension = function(filename, newext) { + return path.basename(filename, path.extname(filename))+newext; +} + module.exports = BaseGenerator; diff --git a/lib/generators/json.js b/lib/generators/json.js index 02a0536..6dc468e 100644 --- a/lib/generators/json.js +++ b/lib/generators/json.js @@ -24,7 +24,7 @@ Generator.prototype.writeParsedFile = function(page, input) { sections: page.sections }; - var output = path.basename(input, path.extname(input))+".json"; + var output = that.changeExtension(input, ".json"); output = path.join(that.options.output, output); return fs.writeFile( @@ -41,11 +41,12 @@ Generator.prototype.langsIndex = function(langs) { if (langs.length == 0) return Q.reject("Need at least one language"); var mainLang = _.first(langs).lang; + var readme = that.changeExtension(that.book.readmeFile, ".json"); return Q() .then(function() { return fs.readFile( - path.join(that.options.output, mainLang, "README.json") + path.join(that.options.output, mainLang, readme) ); }) .then(function(content) { |