Skip to content

Commit 1a5ea33

Browse files
authored
feat(astro): add sensible default canonical url (#437)
1 parent 0e7cf3c commit 1a5ea33

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

packages/astro/src/default/layouts/Layout.astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface Props {
1111
}
1212
const { title, meta } = Astro.props;
1313
const faviconUrl = readPublicAsset('favicon.svg');
14+
const canonicalUrl = Astro.site ? new URL(Astro.url.pathname, Astro.site).toString() : null;
1415
---
1516

1617
<!doctype html>
@@ -20,6 +21,7 @@ const faviconUrl = readPublicAsset('favicon.svg');
2021
<title slot="title">{title}</title>
2122

2223
<Fragment slot="links">
24+
{canonicalUrl && <link rel="canonical" href={canonicalUrl} />}
2325
{faviconUrl ? <link rel="icon" type="image/svg+xml" href={faviconUrl} /> : null}
2426
<link rel="preconnect" href="https://fonts.googleapis.com" />
2527
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />

0 commit comments

Comments
 (0)