From 096bdaba7aa11d56e0356386faaecb189f3100d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Wed, 17 Feb 2016 17:18:19 +0100 Subject: [PATCH] Fix #537: don't add index.html to links --- lib/output/base.js | 17 ++++++++++++++++- lib/output/website.js | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/output/base.js b/lib/output/base.js index a6cfa0d22..7b527da33 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 e25240c46..1ec0548ea 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); }); }); };