Skip to content

Commit

Permalink
fix: use Astro.site property to generate canonical urls
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredLunde committed Apr 24, 2024
1 parent 7d3387a commit 3fc0612
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
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
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export * from "./SEO.astro";
import { Props } from "./SEO.astro";

// @ts-ignore
export type SEOProps = Props;
export type SEOProps = Props;

0 comments on commit 3fc0612

Please sign in to comment.