summaryrefslogtreecommitdiffstats
path: root/bin/gitbook.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-04-06 13:59:58 -0700
committerSamy Pessé <samypesse@gmail.com>2014-04-06 13:59:58 -0700
commitd1e55aef8edb9def83b580ea0f3209e34968e73d (patch)
tree06fae589bc6366221595a0ac45d0badf6817c54a /bin/gitbook.js
parentfde66ed8494ddbc3e6e60bc8162fd97a1d1d5ac2 (diff)
downloadgitbook-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-xbin/gitbook.js41
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);
});
})