mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-03 20:20:35 +00:00
generate upto URL with 4 segments to support sites with sections (#2532)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'gitbook': minor
|
||||
---
|
||||
|
||||
Support resolution of new site URLs with sections
|
||||
@@ -31,6 +31,39 @@ describe('getURLLookupAlternatives', () => {
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(getURLLookupAlternatives(new URL('https://docs.mycompany.com/a/b/c/d'))).toEqual({
|
||||
revision: undefined,
|
||||
changeRequest: undefined,
|
||||
basePath: undefined,
|
||||
urls: [
|
||||
{
|
||||
extraPath: 'a/b/c/d',
|
||||
url: 'https://docs.mycompany.com/',
|
||||
primary: false,
|
||||
},
|
||||
{
|
||||
extraPath: 'b/c/d',
|
||||
url: 'https://docs.mycompany.com/a',
|
||||
primary: false,
|
||||
},
|
||||
{
|
||||
extraPath: 'c/d',
|
||||
url: 'https://docs.mycompany.com/a/b',
|
||||
primary: false,
|
||||
},
|
||||
{
|
||||
extraPath: 'd',
|
||||
url: 'https://docs.mycompany.com/a/b/c',
|
||||
primary: false,
|
||||
},
|
||||
{
|
||||
extraPath: '',
|
||||
url: 'https://docs.mycompany.com/a/b/c/d',
|
||||
primary: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('should not match before the variant for a variant url', () => {
|
||||
@@ -216,29 +249,34 @@ describe('getURLLookupAlternatives', () => {
|
||||
});
|
||||
|
||||
it('should limit depth', () => {
|
||||
expect(getURLLookupAlternatives(new URL('https://docs.mycompany.com/a/b/c/d'))).toEqual({
|
||||
expect(getURLLookupAlternatives(new URL('https://docs.mycompany.com/a/b/c/d/e'))).toEqual({
|
||||
revision: undefined,
|
||||
changeRequest: undefined,
|
||||
basePath: undefined,
|
||||
urls: [
|
||||
{
|
||||
extraPath: 'a/b/c/d',
|
||||
extraPath: 'a/b/c/d/e',
|
||||
url: 'https://docs.mycompany.com/',
|
||||
primary: false,
|
||||
},
|
||||
{
|
||||
extraPath: 'b/c/d',
|
||||
extraPath: 'b/c/d/e',
|
||||
url: 'https://docs.mycompany.com/a',
|
||||
primary: false,
|
||||
},
|
||||
{
|
||||
extraPath: 'c/d',
|
||||
extraPath: 'c/d/e',
|
||||
url: 'https://docs.mycompany.com/a/b',
|
||||
primary: false,
|
||||
},
|
||||
{
|
||||
extraPath: 'd',
|
||||
extraPath: 'd/e',
|
||||
url: 'https://docs.mycompany.com/a/b/c',
|
||||
primary: false,
|
||||
},
|
||||
{
|
||||
extraPath: 'e',
|
||||
url: 'https://docs.mycompany.com/a/b/c/d',
|
||||
primary: true,
|
||||
},
|
||||
],
|
||||
@@ -269,7 +307,12 @@ describe('getURLLookupAlternatives', () => {
|
||||
{
|
||||
extraPath: 'c/d',
|
||||
url: 'https://docs.mycompany.com/a/~/b',
|
||||
primary: false,
|
||||
},
|
||||
{
|
||||
extraPath: 'd',
|
||||
primary: true,
|
||||
url: 'https://docs.mycompany.com/a/~/b/c',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@@ -90,8 +90,8 @@ export function getURLLookupAlternatives(input: URL) {
|
||||
pushAlternative(noPathURL, url.pathname.slice(1));
|
||||
}
|
||||
|
||||
// Otherwise match with the first two segments of the path
|
||||
for (let i = 1; i <= 3; i++) {
|
||||
// Otherwise match with the first four segments of the path
|
||||
for (let i = 1; i <= 4; i++) {
|
||||
if (pathSegments.length >= i) {
|
||||
const shortURL = new URL(url);
|
||||
shortURL.pathname = pathSegments.slice(0, i).join('/');
|
||||
|
||||
Reference in New Issue
Block a user