summaryrefslogtreecommitdiffstats
path: root/lib/output/base.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-17 17:04:23 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-17 17:04:23 +0100
commitd22c1f57e505eda6afe80fb6fe3a6b787d4aa699 (patch)
tree45d30347eb3dcc0d207247052cc2eb531149b262 /lib/output/base.js
parentdac00be7b5a4aefa9cc3f63e5d94e729269bdfb0 (diff)
downloadgitbook-d22c1f57e505eda6afe80fb6fe3a6b787d4aa699.zip
gitbook-d22c1f57e505eda6afe80fb6fe3a6b787d4aa699.tar.gz
gitbook-d22c1f57e505eda6afe80fb6fe3a6b787d4aa699.tar.bz2
Generate index.html instead of README.html
Diffstat (limited to 'lib/output/base.js')
-rw-r--r--lib/output/base.js25
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/output/base.js b/lib/output/base.js
index 638ee25..a6cfa0d 100644
--- a/lib/output/base.js
+++ b/lib/output/base.js
@@ -3,6 +3,7 @@ var Ignore = require('ignore');
var path = require('path');
var Promise = require('../utils/promise');
+var pathUtil = require('../utils/path');
var PluginsManager = require('../plugins');
var TemplateEngine = require('../template');
var gitbook = require('../gitbook');
@@ -30,6 +31,9 @@ function Output(book) {
this.ignore = Ignore();
}
+// Default extension for output
+Output.prototype.defaultExtension = '.html';
+
// Start the generation, for a parsed book
Output.prototype.generate = function() {
var that = this;
@@ -126,7 +130,7 @@ Output.prototype.finish = function() {
// Resolve an HTML link
Output.prototype.onRelativeLink = function(currentPage, href) {
var to = this.book.getPage(href);
- if (to) return to.outputPath();
+ if (to) return this.outputPath(to.path);
return href;
};
@@ -166,4 +170,23 @@ Output.prototype.getPageContext = function(page) {
);
};
+
+// Filename for output
+// READMEs are replaced by index.html
+Output.prototype.outputPath = function(filename, ext) {
+ ext = ext || this.defaultExtension;
+ var output;
+
+ if (
+ path.basename(filename, path.extname(filename)) == 'README' ||
+ output == this.book.readme.path
+ ) {
+ output = path.join(path.dirname(output), 'index'+ext);
+ } else {
+ output = pathUtil.setExtension(output, ext);
+ }
+
+ return output;
+};
+
module.exports = Output;