Fix #537: don't add index.html to links

This commit is contained in:
Samy Pessé
2016-02-17 17:18:19 +01:00
parent d22c1f57e5
commit 096bdaba7a
2 changed files with 17 additions and 2 deletions
+16 -1
View File
@@ -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;
+1 -1
View File
@@ -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);
});
});
};