From 3fc06124cc06c0e329a875ed3d101da69d657e70 Mon Sep 17 00:00:00 2001 From: Jared Lunde Date: Wed, 24 Apr 2024 11:06:50 -0700 Subject: [PATCH] fix: use Astro.site property to generate canonical urls --- src/SEO.astro | 5 ++++- src/index.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/SEO.astro b/src/SEO.astro index 559f50e..ed66eaf 100644 --- a/src/SEO.astro +++ b/src/SEO.astro @@ -128,13 +128,16 @@ if (Astro.props.title) { } else if (Astro.props.titleDefault) { updatedTitle = Astro.props.titleDefault; } + +const baseUrl = Astro.site ?? Astro.url; +const defaultCanonicalUrl = new URL(Astro.url.pathname + Astro.url.search, baseUrl); --- {updatedTitle ? : null} {Astro.props.charset ? <meta charset={Astro.props.charset} /> : null} -<link rel="canonical" href={Astro.props.canonical || Astro.url.href} /> +<link rel="canonical" href={Astro.props.canonical || defaultCanonicalUrl.href} /> { Astro.props.description ? ( diff --git a/src/index.ts b/src/index.ts index 5421f4e..4b8c82e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,4 +8,4 @@ export * from "./SEO.astro"; import { Props } from "./SEO.astro"; // @ts-ignore -export type SEOProps = Props; \ No newline at end of file +export type SEOProps = Props;