diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/generate/fs.js | 12 | ||||
-rw-r--r-- | lib/generate/index.js | 1 | ||||
-rw-r--r-- | lib/generate/pdf/Index.js | 56 | ||||
-rw-r--r-- | lib/generate/site/index.js | 13 |
4 files changed, 71 insertions, 11 deletions
diff --git a/lib/generate/fs.js b/lib/generate/fs.js index c43225e..3338781 100644 --- a/lib/generate/fs.js +++ b/lib/generate/fs.js @@ -27,13 +27,21 @@ var getFiles = function(path) { }); ig.on('end', function() { - d.resolve(files); + // Normalize paths on Windows + if(process.platform === 'win32') { + return d.resolve(files.map(function(file) { + return file.replace(/\\/g, '/'); + })); + } + + // Simply return paths otherwise + return d.resolve(files); }); ig.on('error', d.reject); return d.promise; -} +}; module.exports = { list: getFiles, diff --git a/lib/generate/index.js b/lib/generate/index.js index 4ed9f08..38e7503 100644 --- a/lib/generate/index.js +++ b/lib/generate/index.js @@ -9,6 +9,7 @@ var parse = require("../parse"); var generators = { "site": require("./site"), "page": require("./page"), + "pdf": require("./pdf"), "json": require("./json") }; diff --git a/lib/generate/pdf/Index.js b/lib/generate/pdf/Index.js new file mode 100644 index 0000000..680bda3 --- /dev/null +++ b/lib/generate/pdf/Index.js @@ -0,0 +1,56 @@ +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, { + format: "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.format + ].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;
\ No newline at end of file diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js index 487b6d6..bf711d3 100644 --- a/lib/generate/site/index.js +++ b/lib/generate/site/index.js @@ -33,6 +33,7 @@ Generator.prototype.convertFile = function(content, _input) { var progress = parse.progress(this.options.navigation, _input); _output = _input.replace(".md", ".html"); + if (_output == "README.html") _output = "index.html"; var input = path.join(this.options.input, _input); var output = path.join(this.options.output, _output); @@ -78,15 +79,9 @@ Generator.prototype.finish = function() { var that = this; return fs.copy( - path.join(that.options.output, 'README.html'), - path.join(that.options.output, 'index.html') - ) - .then(function() { - return fs.copy( - path.join(that.options.theme, "assets"), - path.join(that.options.output, "gitbook") - ); - }); + path.join(that.options.theme, "assets"), + path.join(that.options.output, "gitbook") + ); }; module.exports = Generator;
\ No newline at end of file |