diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-10-12 20:56:32 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-10-12 20:56:36 +0200 |
commit | 2fff291cad069bb28a78630430922910344a6206 (patch) | |
tree | fa07beffc505b2b30891e23b5a5de8d29ca82e89 | |
parent | baea45d9246dc35abe19d2815a5f4604baa1cf23 (diff) | |
download | gitbook-2fff291cad069bb28a78630430922910344a6206.zip gitbook-2fff291cad069bb28a78630430922910344a6206.tar.gz gitbook-2fff291cad069bb28a78630430922910344a6206.tar.bz2 |
Readme should always be generated as "index.html"
-rw-r--r-- | packages/gitbook/src/models/__tests__/uriIndex.js | 11 | ||||
-rw-r--r-- | packages/gitbook/src/output/__tests__/website.js | 11 | ||||
-rw-r--r-- | packages/gitbook/src/output/preparePages.js | 6 |
3 files changed, 22 insertions, 6 deletions
diff --git a/packages/gitbook/src/models/__tests__/uriIndex.js b/packages/gitbook/src/models/__tests__/uriIndex.js index 4448683..f3be40b 100644 --- a/packages/gitbook/src/models/__tests__/uriIndex.js +++ b/packages/gitbook/src/models/__tests__/uriIndex.js @@ -13,7 +13,6 @@ describe('URIIndex', () => { }); describe('.resolve', () => { - it('should resolve a basic file path', () => { expect(index.resolve('README.md')).toBe('index.html'); }); @@ -37,11 +36,9 @@ describe('URIIndex', () => { it('should preserve hash', () => { expect(index.resolve('hello/test.md#myhash')).toBe('hello/test.html#myhash'); }); - }); describe('.resolveToURL', () => { - it('should resolve a basic file path with directory index', () => { expect(index.resolveToURL('README.md')).toBe('./'); }); @@ -49,11 +46,9 @@ describe('URIIndex', () => { it('should resolve a basic file path with directory index', () => { expect(index.resolveToURL('hello/README.md')).toBe('hello/'); }); - }); describe('.resolveFrom', () => { - it('should resolve correctly in same directory', () => { expect(index.resolveFrom('README.md', 'world.md')).toBe('world.html'); }); @@ -77,7 +72,13 @@ describe('URIIndex', () => { it('should not fail for absolute url', () => { expect(index.resolveFrom('README.md', 'http://google.fr')).toBe('http://google.fr'); }); + }); + describe('.append', () => { + it('should normalize the filename', () => { + const newIndex = index.append('append//sometest.md', 'append/sometest.html'); + expect(newIndex.resolve('append/sometest.md')).toBe('append/sometest.html'); + }); }); }); diff --git a/packages/gitbook/src/output/__tests__/website.js b/packages/gitbook/src/output/__tests__/website.js index f81464d..4c10f1e 100644 --- a/packages/gitbook/src/output/__tests__/website.js +++ b/packages/gitbook/src/output/__tests__/website.js @@ -12,6 +12,17 @@ describe('WebsiteGenerator', () => { }); }); + it('should generate an index.html for custom README', () => { + return generateMock(WebsiteGenerator, { + 'CustomReadme.md': 'Hello World', + 'book.json': '{ "structure": { "readme": "CustomReadme.md" } }' + }) + .then((folder) => { + expect(folder).toHaveFile('index.html'); + expect(folder).toNotHaveFile('CustomReadme.html'); + }); + }); + describe('Glossary', () => { let folder; diff --git a/packages/gitbook/src/output/preparePages.js b/packages/gitbook/src/output/preparePages.js index ba8519f..0cf1412 100644 --- a/packages/gitbook/src/output/preparePages.js +++ b/packages/gitbook/src/output/preparePages.js @@ -11,6 +11,7 @@ const parseURIIndexFromPages = require('../parse/parseURIIndexFromPages'); function preparePages(output) { const book = output.getBook(); const logger = book.getLogger(); + const readme = book.getReadme(); if (book.isMultilingual()) { return Promise(output); @@ -19,7 +20,10 @@ function preparePages(output) { return Parse.parsePagesList(book) .then((pages) => { logger.info.ln('found', pages.size, 'pages'); - const urls = parseURIIndexFromPages(pages); + let urls = parseURIIndexFromPages(pages); + + // Readme should always generate an index.html + urls = urls.append(readme.getFile().getPath(), 'index.html'); return output.merge({ pages, |