summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-17 17:18:19 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-17 17:18:19 +0100
commit096bdaba7aa11d56e0356386faaecb189f3100d4 (patch)
treedc45b9c3a354a1a037e77cfc5fa002738514a9a0 /lib
parentd22c1f57e505eda6afe80fb6fe3a6b787d4aa699 (diff)
downloadgitbook-096bdaba7aa11d56e0356386faaecb189f3100d4.zip
gitbook-096bdaba7aa11d56e0356386faaecb189f3100d4.tar.gz
gitbook-096bdaba7aa11d56e0356386faaecb189f3100d4.tar.bz2
Fix #537: don't add index.html to links
Diffstat (limited to 'lib')
-rw-r--r--lib/output/base.js17
-rw-r--r--lib/output/website.js2
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/output/base.js b/lib/output/base.js
index a6cfa0d..7b527da 100644
--- a/lib/output/base.js
+++ b/lib/output/base.js
@@ -4,6 +4,7 @@ var path = require('path');
var Promise = require('../utils/promise');
var pathUtil = require('../utils/path');
+var location = require('../utils/location');
var PluginsManager = require('../plugins');
var TemplateEngine = require('../template');
var gitbook = require('../gitbook');
@@ -130,7 +131,9 @@ Output.prototype.finish = function() {
// Resolve an HTML link
Output.prototype.onRelativeLink = function(currentPage, href) {
var to = this.book.getPage(href);
- if (to) return this.outputPath(to.path);
+
+ // Replace by an .html link
+ if (to) href = this.outputUrl(to.path);
return href;
};
@@ -189,4 +192,16 @@ Output.prototype.outputPath = function(filename, ext) {
return output;
};
+// Filename for output
+// /test/index.html -> /test/
+Output.prototype.outputUrl = function(filename, ext) {
+ var href = this.outputPath(filename, ext);
+
+ if (path.basename(href) == 'index.html') {
+ href = path.dirname(href) + '/';
+ }
+
+ return location.normalize(href);
+};
+
module.exports = Output;
diff --git a/lib/output/website.js b/lib/output/website.js
index e25240c..1ec0548 100644
--- a/lib/output/website.js
+++ b/lib/output/website.js
@@ -78,7 +78,7 @@ WebsiteOutput.prototype.prepare = function() {
// Transform a '.md' into a '.html' (README -> index)
that.env.addFilter('contentURL', function(s) {
- return that.outputPath(s);
+ return that.onRelativeLink(null, s);
});
});
};