diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-11-16 10:16:52 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-11-16 10:16:52 +0100 |
commit | f9df7545ad0d3a0c1fb08e1442fe99cf286cd1cc (patch) | |
tree | 602e023a3ff5c660b8f4bc9bc942062443c9c011 /lib | |
parent | 5d907f234e8fe04755714769c3b5b384a6b639b8 (diff) | |
parent | 9b7a90afef5a19c97c45339a3ccc4ebc3db36397 (diff) | |
download | gitbook-f9df7545ad0d3a0c1fb08e1442fe99cf286cd1cc.zip gitbook-f9df7545ad0d3a0c1fb08e1442fe99cf286cd1cc.tar.gz gitbook-f9df7545ad0d3a0c1fb08e1442fe99cf286cd1cc.tar.bz2 |
Merge pull request #1014 from GitbookIO/fix/1013
Fix #1013: prioritize structure defined in book.json
Diffstat (limited to 'lib')
-rw-r--r-- | lib/book.js | 35 | ||||
-rw-r--r-- | lib/configuration.js | 8 |
2 files changed, 27 insertions, 16 deletions
diff --git a/lib/book.js b/lib/book.js index 39d4719..cb00ab1 100644 --- a/lib/book.js +++ b/lib/book.js @@ -356,10 +356,10 @@ Book.prototype.parsePlugins = function() { // Parse readme to extract defaults title and description Book.prototype.parseReadme = function() { var that = this; - var structure = that.config.getStructure('readme'); - that.log.debug.ln('start parsing readme:', structure); + var filename = that.config.getStructure('readme', true); + that.log.debug.ln('start parsing readme:', filename); - return that.findFile(structure) + return that.findFile(filename) .then(function(readme) { if (!readme) throw 'No README file'; if (!_.contains(that.files, readme.path)) throw 'README file is ignored'; @@ -390,10 +390,10 @@ Book.prototype.parseReadme = function() { Book.prototype.parseLangs = function() { var that = this; - var structure = that.config.getStructure('langs'); - that.log.debug.ln('start parsing languages index:', structure); + var filename = that.config.getStructure('langs', true); + that.log.debug.ln('start parsing languages index:', filename); - return that.findFile(structure) + return that.findFile(filename) .then(function(langs) { if (!langs) return []; @@ -421,10 +421,10 @@ Book.prototype.parseLangs = function() { Book.prototype.parseSummary = function() { var that = this; - var structure = that.config.getStructure('summary'); - that.log.debug.ln('start parsing summary:', structure); + var filename = that.config.getStructure('summary', true); + that.log.debug.ln('start parsing summary:', filename); - return that.findFile(structure) + return that.findFile(filename) .then(function(summary) { if (!summary) throw 'No SUMMARY file'; @@ -459,10 +459,10 @@ Book.prototype.parseSummary = function() { Book.prototype.parseGlossary = function() { var that = this; - var structure = that.config.getStructure('glossary'); - that.log.debug.ln('start parsing glossary: ', structure); + var filename = that.config.getStructure('glossary', true); + that.log.debug.ln('start parsing glossary: ', filename); - return that.findFile(structure) + return that.findFile(filename) .then(function(glossary) { if (!glossary) return []; @@ -600,12 +600,19 @@ Book.prototype.parsePage = function(filename, options) { Book.prototype.findFile = function(filename) { var that = this; - return _.reduce(parsers.extensions, function(prev, ext) { + var ext = path.extname(filename); + var basename = path.basename(filename, ext); + + // Ordered list of extensions to test + var exts = parsers.extensions; + if (ext) exts = _.uniq([ext].concat(exts)); + + return _.reduce(exts, function(prev, ext) { return prev.then(function(output) { // Stop if already find a parser if (output) return output; - var filepath = filename+ext; + var filepath = basename+ext; return that.fileExists(filepath) .then(function(exists) { diff --git a/lib/configuration.js b/lib/configuration.js index 86478c8..dd95585 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -181,8 +181,12 @@ Configuration.prototype.dump = function() { }; // Get structure file -Configuration.prototype.getStructure = function(name) { - return this.options.structure[name].split('.').slice(0, -1).join('.'); +Configuration.prototype.getStructure = function(name, dontStripExt) { + var filename = this.options.structure[name]; + if (dontStripExt) return filename; + + filename = filename.split('.').slice(0, -1).join('.'); + return filename; }; // Return normalized language |