summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--bin/build.js8
-rwxr-xr-xbin/gitbook.js32
-rw-r--r--lib/generate/index.js1
-rw-r--r--lib/generate/pdf/index.js56
5 files changed, 33 insertions, 69 deletions
diff --git a/README.md b/README.md
index e09aee1..b2d28fd 100644
--- a/README.md
+++ b/README.md
@@ -31,7 +31,7 @@ Options for commands `build` and `serve` are:
```
-o, --output <directory> Path to output directory, defaults to ./_book
--f, --format <name> Change generation format, defaults to site, availables are: site, page, pdf, json
+-f, --format <name> Change generation format, defaults to site, availables are: site, page, pdf, json, mobi, epub
--config <config file> Configuration file to use, defaults to book.json
```
@@ -99,8 +99,7 @@ You can publish your books to our index by visiting [GitBook.io](http://www.gitb
GitBook can generate your book in the following formats:
* **Static Website**: This is the default format. It generates a complete interactive static website that can be, for example, hosted on GitHub Pages.
-* **PDF**: A complete PDF book with exercise solutions at the end of the book. Generate this format using: ```gitbook pdf ./myrepo```. You need to have [gitbook-pdf](https://github.com/GitbookIO/gitbook-pdf) installed.
-* **eBook**: A complete eBook with exercise solutions at the end of the book. Generate this format using: ```gitbook ebook ./myrepo```. You need to have [ebook-convert](http://manual.calibre-ebook.com/cli/ebook-convert.html) installed.
+* **eBook**: A complete eBook with exercise solutions at the end of the book. Generate this format using: ```gitbook ebook ./myrepo```. You need to have [ebook-convert](http://manual.calibre-ebook.com/cli/ebook-convert.html) installed. The output format could be **PDF**, **ePub** or **MOBI**.
* **Single Page**: The book will be stored in a single printable HTML page. This format is used for conversion to PDF or eBook. Generate this format using: ```gitbook build ./myrepo -f page```.
* **JSON**: This format is used for debugging or extracting metadata from a book. Generate this format using: ```gitbook build ./myrepo -f json```.
diff --git a/bin/build.js b/bin/build.js
index 5894d00..196bead 100644
--- a/bin/build.js
+++ b/bin/build.js
@@ -16,6 +16,11 @@ var buildCommand = function(command) {
};
+var buildEbookCommand = function(command) {
+ return buildCommand(command)
+ .option('-c, --cover <path>', 'Cover image, default is cover.jpg if exists');
+};
+
var makeBuildFunc = function(converter) {
return function(dir, options) {
dir = dir || process.cwd();
@@ -43,5 +48,6 @@ var makeBuildFunc = function(converter) {
module.exports = {
folder: makeBuildFunc(generate.folder),
file: makeBuildFunc(generate.file),
- command: buildCommand
+ command: buildCommand,
+ commandEbook: buildEbookCommand
};
diff --git a/bin/gitbook.js b/bin/gitbook.js
index c5a51a4..c2c2e31 100755
--- a/bin/gitbook.js
+++ b/bin/gitbook.js
@@ -80,24 +80,40 @@ build.command(prog.command('serve [source_dir]'))
generate();
});
-build.command(prog.command('pdf [source_dir]'))
+build.commandEbook(prog.command('ebook [source_dir]'))
+.description('Build a gitbook as a eBook (format detected according to the extension)')
+.action(function(dir, options) {
+ var ext = options.output ? path.extname(options.output) : "epub";
+
+ build.file(dir, _.extend(options, {
+ extension: ext,
+ format: "ebook"
+ }));
+});
+
+build.commandEbook(prog.command('pdf [source_dir]'))
.description('Build a gitbook as a PDF')
-.option('-pf, --paperformat <format>', 'PDF paper format (default is A4): "5in*7.5in", "10cm*20cm", "A4", "Letter"')
.action(function(dir, options) {
build.file(dir, _.extend(options, {
extension: "pdf",
- format: "pdf"
+ format: "ebook"
}));
});
-build.command(prog.command('ebook [source_dir]'))
-.description('Build a gitbook as a eBook')
-.option('-c, --cover <path>', 'Cover image, default is cover.jpg if exists')
+build.commandEbook(prog.command('epub [source_dir]'))
+.description('Build a gitbook as a ePub book')
.action(function(dir, options) {
- var ext = options.output ? path.extname(options.output) : "epub";
+ build.file(dir, _.extend(options, {
+ extension: "epub",
+ format: "ebook"
+ }));
+});
+build.commandEbook(prog.command('mobi [source_dir]'))
+.description('Build a gitbook as a Mobi book')
+.action(function(dir, options) {
build.file(dir, _.extend(options, {
- extension: ext,
+ extension: "mobi",
format: "ebook"
}));
});
diff --git a/lib/generate/index.js b/lib/generate/index.js
index 6b75dea..bbcec0b 100644
--- a/lib/generate/index.js
+++ b/lib/generate/index.js
@@ -11,7 +11,6 @@ var Plugin = require("./plugin");
var generators = {
"site": require("./site"),
"page": require("./page"),
- "pdf": require("./pdf"),
"ebook": require("./ebook"),
"json": require("./json")
};
diff --git a/lib/generate/pdf/index.js b/lib/generate/pdf/index.js
deleted file mode 100644
index 185eabd..0000000
--- a/lib/generate/pdf/index.js
+++ /dev/null
@@ -1,56 +0,0 @@
-var util = require("util");
-var path = require("path");
-var Q = require("q");
-var _ = require("lodash");
-var exec = require('child_process').exec;
-
-var fs = require("../fs");
-var parse = require("../../parse");
-var BaseGenerator = require("../page");
-
-/*
- * This generator inherits from the single page generator
- * and convert the page output to pdf using gitbook-pdf
- */
-var Generator = function() {
- BaseGenerator.apply(this, arguments);
-
- // Options for PDF generation
- this.options = _.defaults(this.options, {
- paperformat: "A4"
- });
-};
-util.inherits(Generator, BaseGenerator);
-
-Generator.prototype.finish = function() {
- var that = this;
-
- return BaseGenerator.prototype.finish.apply(this)
- .then(function() {
- var d = Q.defer();
-
- var command = [
- "gitbook-pdf",
- "generate",
- path.join(that.options.output, "index.html"),
- path.join(that.options.output, "index.pdf"),
- "--format="+that.options.paperformat
- ].join(" ");
-
- exec(command, function (error, stdout, stderr) {
- if (error) {
- if (error.code == 127) {
- error.message = "Need to install gitbook-pdf using: npm install gitbook-pdf -g";
- } else {
- error.message = error.message + " "+stdout;
- }
- return d.reject(error);
- }
- d.resolve();
- });
-
- return d.promise;
- });
-};
-
-module.exports = Generator;