mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-20 17:43:24 +00:00
When using structure.readme, fix link to readme to resolve to index.html
This commit is contained in:
@@ -189,6 +189,11 @@ Output.prototype.onRelativeLink = function(currentPage, href) {
|
||||
if (to) {
|
||||
href = to.path;
|
||||
|
||||
// Change README path to be "index.html"
|
||||
if (href == this.book.readme.path) {
|
||||
href = 'index.html';
|
||||
}
|
||||
|
||||
// Recalcul as relative link
|
||||
href = currentPage.relative(href);
|
||||
|
||||
|
||||
+3
-1
@@ -19,7 +19,6 @@ require('./git');
|
||||
require('./plugins');
|
||||
require('./template');
|
||||
require('./conrefs');
|
||||
require('./ignore');
|
||||
|
||||
// Page and HTML generation
|
||||
require('./page');
|
||||
@@ -30,5 +29,8 @@ require('./output-json');
|
||||
require('./output-website');
|
||||
require('./output-ebook');
|
||||
|
||||
require('./structure');
|
||||
require('./ignore');
|
||||
|
||||
// Misc
|
||||
require('./init');
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
var fs = require('fs');
|
||||
|
||||
var mock = require('./mock');
|
||||
var WebsiteOutput = require('../lib/output/website');
|
||||
|
||||
/*
|
||||
|
||||
Testing using configuration "structure" to use custom Readme/Summary/Glossary paths
|
||||
*/
|
||||
|
||||
describe('Structure', function() {
|
||||
var output;
|
||||
|
||||
before(function() {
|
||||
return mock.outputBook(WebsiteOutput, {
|
||||
'book.json': {
|
||||
structure: {
|
||||
readme: 'intro.md'
|
||||
}
|
||||
},
|
||||
'SUMMARY.md': '* [Test](test.md)',
|
||||
'intro.md': 'This is the intro',
|
||||
'test.md': 'Go to [intro](intro.md)'
|
||||
})
|
||||
.then(function(_output) {
|
||||
output = _output;
|
||||
});
|
||||
});
|
||||
|
||||
it('should generate index.html', function() {
|
||||
output.should.have.file('index.html');
|
||||
});
|
||||
|
||||
it('should generate test.html', function() {
|
||||
output.should.have.file('test.html');
|
||||
});
|
||||
|
||||
it('should correctly resolve link to Readme', function() {
|
||||
var readme = fs.readFileSync(output.resolve('test.html'), 'utf-8');
|
||||
|
||||
readme.should.be.html({
|
||||
'.page-inner a': {
|
||||
count: 1,
|
||||
text: 'intro',
|
||||
attributes: {
|
||||
href: './'
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user