build(aio): fix paths to "index" pages

Content pages like `tutorial/index.md` were being mapped to `tutorial.index.json`,
which meant that they could only be rendered if you browsed to `/tutorial/index`.

This didn't sit well so now these pages are mapped to `tutorial.json`, which
means that you browser to them via `/tutorial/` or just `/tutorial`.

Fixed #15335
This commit is contained in:
Peter Bacon Darwin
2017-03-21 07:02:58 +00:00
committed by Miško Hevery
parent c9710d4fb5
commit fc1f6efe0d
5 changed files with 43 additions and 8 deletions

View File

@ -155,5 +155,12 @@ describe('DocumentService', () => {
expect(backend.connectionsArray[0].request.url).toEqual(CONTENT_URL_PREFIX + 'index.json');
});
it('should map the "folder" locations to the correct document request', () => {
const { service, backend, location } = getServices('guide/');
service.currentDocument.subscribe();
expect(backend.connectionsArray[0].request.url).toEqual(CONTENT_URL_PREFIX + 'guide.json');
});
});
});

View File

@ -63,8 +63,11 @@ export class DocumentService {
private computePath(url: string) {
url = url.match(/[^#?]*/)[0]; // strip off fragment and query
url = '/' + url;
url = url.endsWith('/') ? url + 'index' : url;
return 'content/docs' + url + '.json';
url = url.replace(/\/$/, ''); // strip off trailing slash
if (url === '') {
// deal with root url
url = 'index';
}
return 'content/docs/' + url + '.json';
}
}