diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-06 19:10:22 -0700 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-06 19:10:22 -0700 |
commit | 4b64c8701144906a09f4f39447641139afdbc763 (patch) | |
tree | cfc47cc0c59eaa0ef0a59819b5d0eb3338102787 /lib/generate/ebook/index.js | |
parent | 4c36c592c1cccfbbb7843d74846a5f908bfcab4e (diff) | |
download | gitbook-4b64c8701144906a09f4f39447641139afdbc763.zip gitbook-4b64c8701144906a09f4f39447641139afdbc763.tar.gz gitbook-4b64c8701144906a09f4f39447641139afdbc763.tar.bz2 |
Add base ebook generator using ebook-convert
Diffstat (limited to 'lib/generate/ebook/index.js')
-rw-r--r-- | lib/generate/ebook/index.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/generate/ebook/index.js b/lib/generate/ebook/index.js new file mode 100644 index 0000000..8d81bfc --- /dev/null +++ b/lib/generate/ebook/index.js @@ -0,0 +1,54 @@ +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 ebook + */ +var Generator = function() { + BaseGenerator.apply(this, arguments); + + // Options for eBook generation + this.options = _.defaults(this.options, { + extension: "epub" + }); +}; +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 = [ + "ebook-convert", + path.join(that.options.output, "index.html"), + path.join(that.options.output, "index."+that.options.extension) + ].join(" "); + + exec(command, function (error, stdout, stderr) { + if (error) { + if (error.code == 127) { + error.message = "Need to install ebook-convert from Calibre"; + } else { + error.message = error.message + " "+stdout; + } + return d.reject(error); + } + d.resolve(); + }); + + return d.promise; + }); +}; + +module.exports = Generator; |