diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-06 13:59:58 -0700 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-06 13:59:58 -0700 |
commit | d1e55aef8edb9def83b580ea0f3209e34968e73d (patch) | |
tree | 06fae589bc6366221595a0ac45d0badf6817c54a /bin/gitbook.js | |
parent | fde66ed8494ddbc3e6e60bc8162fd97a1d1d5ac2 (diff) | |
download | gitbook-d1e55aef8edb9def83b580ea0f3209e34968e73d.zip gitbook-d1e55aef8edb9def83b580ea0f3209e34968e73d.tar.gz gitbook-d1e55aef8edb9def83b580ea0f3209e34968e73d.tar.bz2 |
Add support of multi-languages book in command pdf
Diffstat (limited to 'bin/gitbook.js')
-rwxr-xr-x | bin/gitbook.js | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/bin/gitbook.js b/bin/gitbook.js index 136c2a5..03d6bef 100755 --- a/bin/gitbook.js +++ b/bin/gitbook.js @@ -71,13 +71,40 @@ function(dir, outputFile, options) { format: "pdf" }) ) - .then(function() { - console.log("Generating PDF in", outputFile); - return fs.copy( - path.join(tmpDir, "index.pdf"), - outputFile - ) - return fs.remove(tmpDir) + .then(function(_options) { + var copyPDF = function(lang) { + var _outputFile = outputFile; + var _tmpDir = tmpDir; + + if (lang) { + _outputFile = _outputFile.slice(0, -path.extname(_outputFile).length)+"_"+lang+path.extname(_outputFile); + _tmpDir = path.join(_tmpDir, lang); + } + + console.log("Generating PDF in", _outputFile); + return fs.copy( + path.join(_tmpDir, "index.pdf"), + _outputFile + ); + }; + + // Multi-langs book + return Q() + .then(function() { + if (_options.langsSummary) { + console.log("Generating PDFs for all the languages"); + return Q.all( + _.map(_options.langsSummary.list, function(lang) { + return copyPDF(lang.lang); + }) + ); + } else { + return copyPDF(); + } + }) + .then(function() { + return fs.remove(tmpDir); + }) .fail(utils.logError); }); }) |