diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-14 19:48:12 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-14 19:48:12 +0200 |
commit | 05f1eed9cee6ba0cbffb3285803fd6e9760291ef (patch) | |
tree | dbe1340b916dddeb817dabef6a9a6f9832853dd2 /lib/generate/index.js | |
parent | c0ca055bf4c5cbc776b2822afaa3a1efb1b97c19 (diff) | |
download | gitbook-05f1eed9cee6ba0cbffb3285803fd6e9760291ef.zip gitbook-05f1eed9cee6ba0cbffb3285803fd6e9760291ef.tar.gz gitbook-05f1eed9cee6ba0cbffb3285803fd6e9760291ef.tar.bz2 |
Fix #91: Extract defaults title and description from README.md
Diffstat (limited to 'lib/generate/index.js')
-rw-r--r-- | lib/generate/index.js | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/generate/index.js b/lib/generate/index.js index cba9071..48bcaca 100644 --- a/lib/generate/index.js +++ b/lib/generate/index.js @@ -15,6 +15,8 @@ var generators = { "json": require("./json") }; +var defaultDescription = "Book generated using GitBook"; + /* * Use a specific generator to convert a gitbook to a site/pdf/ebook/ * output is always a folder @@ -33,7 +35,7 @@ var generate = function(options) { // Book title, keyword, description title: null, - description: "Book generated using GitBook", + description: null, // Origin github repository id github: null, @@ -43,8 +45,8 @@ var generate = function(options) { theme: path.resolve(__dirname, '../../theme') }); - if (!options.title || !options.input) { - return Q.reject(new Error("Need options: title, input")); + if (!options.input) { + return Q.reject(new Error("Need option input (book input directory)")); } if (!generators[options.generator]) { @@ -103,14 +105,28 @@ var generate = function(options) { return Q.reject(new Error("Invalid gitbook repository, need SUMMARY.md and README.md")); } else { // Generate the book - return fs.readFile(path.join(options.input, "SUMMARY.md"), "utf-8") + 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(_summary) { - options.summary = parse.summary(_summary); + .then(function() { + return fs.readFile(path.join(options.input, "SUMMARY.md"), "utf-8") + .then(function(_summary) { + options.summary = parse.summary(_summary); - // Parse navigation - options.navigation = parse.navigation(options.summary); + // Parse navigation + options.navigation = parse.navigation(options.summary); + }); }) // Copy file and replace markdown file |