diff --git a/.changeset/tiny-lobsters-remember.md b/.changeset/tiny-lobsters-remember.md new file mode 100644 index 000000000..09c57a4d2 --- /dev/null +++ b/.changeset/tiny-lobsters-remember.md @@ -0,0 +1,5 @@ +--- +'gitbook': minor +--- + +Support resolution of new site URLs without the variant prefix /v/ diff --git a/packages/gitbook/src/lib/middleware.test.ts b/packages/gitbook/src/lib/middleware.test.ts index 7efa364f9..6723c6598 100644 --- a/packages/gitbook/src/lib/middleware.test.ts +++ b/packages/gitbook/src/lib/middleware.test.ts @@ -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, }, ], diff --git a/packages/gitbook/src/lib/middleware.ts b/packages/gitbook/src/lib/middleware.ts index f86281d29..c3aef41a9 100644 --- a/packages/gitbook/src/lib/middleware.ts +++ b/packages/gitbook/src/lib/middleware.ts @@ -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('/');