mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 23:55:20 +00:00
Properly redirect to the root page (#3369)
Co-authored-by: Nicolas Dorseuil <nicolas@gitbook.io>
This commit is contained in:
@@ -35,8 +35,9 @@ describe('toPathInSpace', () => {
|
||||
expect(variantInSection.toPathInSpace('some/path/')).toBe('/section/variant/some/path');
|
||||
});
|
||||
|
||||
it('should not add a trailing slash', () => {
|
||||
expect(root.toPathInSpace('')).toBe('');
|
||||
it('should not add an unnecessary trailing slash', () => {
|
||||
// The index page should not be an empty path
|
||||
expect(root.toPathInSpace('')).toBe('/');
|
||||
expect(variantInSection.toPathInSpace('')).toBe('/section/variant');
|
||||
});
|
||||
});
|
||||
@@ -52,8 +53,9 @@ describe('toPathInSite', () => {
|
||||
expect(siteGitBookIO.toPathInSite('some/path/')).toBe('/sitename/some/path');
|
||||
});
|
||||
|
||||
it('should not add a trailing slash', () => {
|
||||
expect(root.toPathInSite('')).toBe('');
|
||||
it('should not add an unnecessary trailing slash', () => {
|
||||
// The index page should not be an empty path
|
||||
expect(root.toPathInSite('')).toBe('/');
|
||||
expect(siteGitBookIO.toPathInSite('')).toBe('/sitename');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -128,7 +128,8 @@ export function createLinker(
|
||||
function joinPaths(prefix: string, path: string): string {
|
||||
const prefixPath = prefix.endsWith('/') ? prefix : `${prefix}/`;
|
||||
const suffixPath = path.startsWith('/') ? path.slice(1) : path;
|
||||
return removeTrailingSlash(prefixPath + suffixPath);
|
||||
const pathWithoutTrailingSlash = removeTrailingSlash(prefixPath + suffixPath);
|
||||
return pathWithoutTrailingSlash === '' ? '/' : pathWithoutTrailingSlash;
|
||||
}
|
||||
|
||||
function removeTrailingSlash(path: string): string {
|
||||
|
||||
Reference in New Issue
Block a user