diff options
Diffstat (limited to 'lib/generate/index.js')
-rw-r--r-- | lib/generate/index.js | 66 |
1 files changed, 47 insertions, 19 deletions
diff --git a/lib/generate/index.js b/lib/generate/index.js index 6a07a21..8c6450c 100644 --- a/lib/generate/index.js +++ b/lib/generate/index.js @@ -67,7 +67,9 @@ var generate = function(options) { // Links "links": { - "about": null + "about": null, + "issues": null, + "contribue": null, } }); @@ -82,7 +84,24 @@ var generate = function(options) { } // Check files to get folder type (book, multilanguage book or neither) - return containsFiles(options.input, ['LANGS.md']) + return Q() + + // Read readme + .then(function() { + return fs.readFile(path.join(options.input, "README.md"), "utf-8") + .then(function(_readme) { + _readme = parse.readme(_readme); + + options.title = options.title || _readme.title; + options.description = options.description || _readme.description || defaultDescription; + }); + }) + + // Detect multi-languages book + .then(function() { + return containsFiles(options.input, ['LANGS.md']) + }) + .then(function(isMultiLang) { // Multi language book if(isMultiLang) { @@ -96,24 +115,34 @@ var generate = function(options) { var generateMultiLang = function(options) { + var langsSummary; options.output = options.output || path.join(options.input, "_book"); // Multi-languages book return fs.readFile(path.join(options.input, "LANGS.md"), "utf-8") - // Generate sub-books + // Clean output folder .then(function(_langsSummary) { - options.langsSummary = parse.langs(_langsSummary); + langsSummary = _langsSummary; + return fs.remove(options.output); + }) + .then(function() { + return fs.mkdirp(options.output); + }) + + // Generate sub-books + .then(function() { + options.langsSummary = parse.langs(langsSummary); // Generated a book for each valid entry - return Q.all( - _.map(options.langsSummary.list, function(entry) { + return _.reduce(options.langsSummary.list, function(prev, entry) { + return prev.then(function() { return generate(_.extend({}, options, { input: path.join(options.input, entry.path), output: path.join(options.output, entry.path) })); }) - ); + }, Q()); }) .then(function() { @@ -170,6 +199,16 @@ var generateBook = function(options) { // Get repo's URL .then(function() { + // Git deactivated + if(options.github === false) { + options.github = null; + return null; + } else if(options.github) { + // Git already specified in options + return options.github; + } + + // Try auto detecting return parse.git.url(options.input) .then(function(_url) { // Get ID of repo @@ -178,7 +217,7 @@ var generateBook = function(options) { return null; }) .then(function(repoId) { - options.github = options.github || repoId; + options.github = repoId; }); }) @@ -203,17 +242,6 @@ var generateBook = function(options) { // Generate the book return Q() - // Read readme - .then(function() { - return fs.readFile(path.join(options.input, "README.md"), "utf-8") - .then(function(_readme) { - _readme = parse.readme(_readme); - - options.title = options.title || _readme.title; - options.description = options.description || _readme.description || defaultDescription; - }); - }) - // Get summary .then(function() { return fs.readFile(path.join(options.input, "SUMMARY.md"), "utf-8") |