summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md11
-rw-r--r--bin/build.js4
-rwxr-xr-xbin/gitbook.js45
-rw-r--r--lib/generate/page/index.js8
4 files changed, 49 insertions, 19 deletions
diff --git a/README.md b/README.md
index 0a90be5..89c0d85 100644
--- a/README.md
+++ b/README.md
@@ -108,3 +108,14 @@ Exercises need to start and finish with a separation bar (```---``` or ```***```
---
+#### Multi-Languages
+
+GitBook supports generation of books written in multiple languages. Each languages should be a sub-directory with a normal GitBook format, and a file named `LANGS.md` should be present at the root of the repository with the following format:
+
+```
+* [English](en/)
+* [French](fr/)
+* [EspaƱol](es/)
+```
+
+You can see a complete example with the [Learn Git](https://github.com/GitbookIO/git) book.
diff --git a/bin/build.js b/bin/build.js
index 49978b8..bea8ff9 100644
--- a/bin/build.js
+++ b/bin/build.js
@@ -47,8 +47,8 @@ var buildFunc = function(dir, options) {
})
.then(function(output) {
console.log("Successfuly built !");
- }, utils.logError)
- .then(_.constant(outputDir));
+ return output;
+ }, utils.logError);
};
module.exports = buildFunc; \ No newline at end of file
diff --git a/bin/gitbook.js b/bin/gitbook.js
index ef842fb..03d6bef 100755
--- a/bin/gitbook.js
+++ b/bin/gitbook.js
@@ -42,10 +42,10 @@ buildCommand(prog
.option('-p, --port <port>', 'Port for server to listen on', 4000),
function(dir, options) {
buildFunc(dir, options)
- .then(function(outputDir) {
+ .then(function(_options) {
console.log();
console.log('Starting server ...');
- return utils.serveDir(outputDir, options.port)
+ return utils.serveDir(_options.output, options.port)
.fail(utils.logError);
})
.then(function() {
@@ -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);
});
})
diff --git a/lib/generate/page/index.js b/lib/generate/page/index.js
index ac815e7..5be40c4 100644
--- a/lib/generate/page/index.js
+++ b/lib/generate/page/index.js
@@ -33,14 +33,6 @@ var Generator = function() {
};
util.inherits(Generator, BaseGenerator);
-Generator.prototype.transferFile = function(input) {
- // ignore
-};
-
-Generator.prototype.transferFolder = function(input) {
- // ignore
-};
-
Generator.prototype.convertFile = function(content, input) {
var that = this;
var json = {