diff --git a/packages/docusaurus-utils/src/__tests__/index.test.ts b/packages/docusaurus-utils/src/__tests__/index.test.ts index a47fc0f15e1a..546ce167cc88 100644 --- a/packages/docusaurus-utils/src/__tests__/index.test.ts +++ b/packages/docusaurus-utils/src/__tests__/index.test.ts @@ -254,6 +254,10 @@ describe('load utils', () => { input: ['/test/', '/', 'ro', 'doc1'], output: '/test/ro/doc1', }, + { + input: ['/', '/', '2020/02/29/leap-day'], + output: '/2020/02/29/leap-day', + }, { input: ['', '/', 'ko', 'hello'], output: '/ko/hello', diff --git a/packages/docusaurus-utils/src/index.ts b/packages/docusaurus-utils/src/index.ts index 2309c680beda..3336bbdfbe05 100644 --- a/packages/docusaurus-utils/src/index.ts +++ b/packages/docusaurus-utils/src/index.ts @@ -256,6 +256,9 @@ export function normalizeUrl(rawUrls: string[]): string { // Dedupe forward slashes in the entire path, avoiding protocol slashes. str = str.replace(/([^:]\/)\/+/g, '$1'); + // Dedupe forward slashes at the beginning of the path. + str = str.replace(/^\/+/g, '/'); + return str; }