mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 02:53:29 +00:00
Fix #537: don't add index.html to links
This commit is contained in:
+16
-1
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user