generate upto URL with 3 segments to support the new site url format (#2493)

Co-authored-by: Samy Pessé <samypesse@gmail.com>
This commit is contained in:
Taran Vohra
2024-09-26 17:16:22 +05:30
committed by GitHub
parent 75f825e4f8
commit e2ef22fc5f
3 changed files with 21 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'gitbook': minor
---
Support resolution of new site URLs without the variant prefix /v/
@@ -22,6 +22,11 @@ describe('getURLLookupAlternatives', () => {
{
extraPath: 'c',
url: 'https://docs.mycompany.com/a/b',
primary: false,
},
{
extraPath: '',
url: 'https://docs.mycompany.com/a/b/c',
primary: true,
},
],
@@ -229,6 +234,11 @@ describe('getURLLookupAlternatives', () => {
{
extraPath: 'c/d',
url: 'https://docs.mycompany.com/a/b',
primary: false,
},
{
extraPath: 'd',
url: 'https://docs.mycompany.com/a/b/c',
primary: true,
},
],
@@ -254,6 +264,11 @@ describe('getURLLookupAlternatives', () => {
{
extraPath: 'b/c/d',
url: 'https://docs.mycompany.com/a/~',
primary: false,
},
{
extraPath: 'c/d',
url: 'https://docs.mycompany.com/a/~/b',
primary: true,
},
],
+1 -1
View File
@@ -91,7 +91,7 @@ export function getURLLookupAlternatives(input: URL) {
}
// Otherwise match with the first two segments of the path
for (let i = 1; i <= 2; i++) {
for (let i = 1; i <= 3; i++) {
if (pathSegments.length >= i) {
const shortURL = new URL(url);
shortURL.pathname = pathSegments.slice(0, i).join('/');