Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/gitbook/src/lib/pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ describe('extractPagePath', () => {
it('returns empty string for root URL', () => {
expect(extractPagePath('https://docs.example.com/api/', baseURL)).toBe('');
});

it('extracts path when base URL is at the root of the domain', () => {
expect(
extractPagePath(
'https://docs.example.com/merchant-account/user-management/sso',
'https://docs.example.com/'
)
).toBe('merchant-account/user-management/sso');
});

it('returns empty string when URL equals root base URL', () => {
expect(extractPagePath('https://docs.example.com/', 'https://docs.example.com/')).toBe('');
});
});

describe('resolveFirstDocument', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/gitbook/src/lib/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,12 @@ export function extractPagePath(url: string, baseURL: string): string | undefine
const urlPath = getURLPathname(url);
const basePath = getURLPathname(baseURL);

if (!urlPath || !basePath) {
if (urlPath === undefined || basePath === undefined) {
return undefined;
}

if (urlPath.startsWith(`${basePath}/`) || urlPath === basePath) {
// When basePath is empty, the site is at the root of the domain, so any path matches
if (basePath === '' || urlPath.startsWith(`${basePath}/`) || urlPath === basePath) {
return removeLeadingSlash(urlPath.slice(basePath.length));
}
}
Expand Down
Loading