Skip to content

Commit 0e37819

Browse files
authored
Merge pull request #95 from jaredLunde:canonical-url-fix
fix: use Astro.site property to generate default canonical urls
2 parents 71e7c25 + 3fc0612 commit 0e37819

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/SEO.astro

+4-1
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,16 @@ if (Astro.props.title) {
128128
} else if (Astro.props.titleDefault) {
129129
updatedTitle = Astro.props.titleDefault;
130130
}
131+
132+
const baseUrl = Astro.site ?? Astro.url;
133+
const defaultCanonicalUrl = new URL(Astro.url.pathname + Astro.url.search, baseUrl);
131134
---
132135

133136
{updatedTitle ? <title set:html={updatedTitle} /> : null}
134137

135138
{Astro.props.charset ? <meta charset={Astro.props.charset} /> : null}
136139

137-
<link rel="canonical" href={Astro.props.canonical || Astro.url.href} />
140+
<link rel="canonical" href={Astro.props.canonical || defaultCanonicalUrl.href} />
138141

139142
{
140143
Astro.props.description ? (

0 commit comments

Comments
 (0)