From 3d2d3094b2c04082337a9e26b7dd92c1924edec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Tue, 26 Nov 2024 21:45:59 +0100 Subject: [PATCH] Fix canonical URL ending with "/" --- packages/gitbook/src/lib/links.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/gitbook/src/lib/links.ts b/packages/gitbook/src/lib/links.ts index 5acf816d11..8a2522bd73 100644 --- a/packages/gitbook/src/lib/links.ts +++ b/packages/gitbook/src/lib/links.ts @@ -79,9 +79,14 @@ export function baseUrl(): string { /** * Create an absolute href in the current content. + * If it's the root URL, the trailing slash will be removed. */ export function absoluteHref(href: string, withHost: boolean = false): string { const base = withHost ? baseUrl() : basePath(); + if (href === '') { + // Remove the trailing slash if it's the root URL + return base.slice(0, -1); + } return `${base}${href.startsWith('/') ? href.slice(1) : href}`; }