fix: ensure canonical URL pathname consistency

This commit is contained in:
ccbikai
2024-11-09 15:46:43 +08:00
parent 7da142ad1e
commit 1d22719070

View File

@@ -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')