Skip to content

Commit

Permalink
Merge pull request #95 from jaredLunde:canonical-url-fix
Browse files Browse the repository at this point in the history
fix: use Astro.site property to generate default canonical urls
  • Loading branch information
jonasmerlin authored Jun 1, 2024
2 parents 71e7c25 + 3fc0612 commit 0e37819
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/SEO.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? <title set:html={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 ? (
Expand Down

0 comments on commit 0e37819

Please sign in to comment.