From 1d2271907098ebe6de1da7f048eabfea2b784869 Mon Sep 17 00:00:00 2001 From: ccbikai Date: Sat, 9 Nov 2024 15:46:43 +0800 Subject: [PATCH] fix: ensure canonical URL pathname consistency --- src/layouts/base.astro | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/layouts/base.astro b/src/layouts/base.astro index 67607199..61f019ee 100644 --- a/src/layouts/base.astro +++ b/src/layouts/base.astro @@ -12,9 +12,9 @@ const { channel } = Astro.props const locale = getEnv(import.meta.env, Astro, 'LOCALE') const seo = channel?.seo -const canonical = SITE_URL.startsWith('http') - ? new URL(SITE_URL).origin + Astro.url.pathname - : Astro.url.origin + Astro.url.pathname +const reqPathname = Astro.url.pathname.replace(/\/$/, '') +const canonical = SITE_URL.startsWith('http') ? new URL(SITE_URL).origin + reqPathname : Astro.url.origin + reqPathname + const { origin, pathname } = new URL(canonical) const twitter = getEnv(import.meta.env, Astro, 'TWITTER')