diff --git a/src/components/Head.astro b/src/components/Head.astro index 79887db..285ce23 100644 --- a/src/components/Head.astro +++ b/src/components/Head.astro @@ -21,6 +21,12 @@ interface Props { const canonicalURL = new URL(Astro.url.pathname, Astro.site); +// For pretty URLs (e.g., /slug), use the pretty URL as canonical +const requestedPath = Astro.request.url.replace(Astro.site?.href || '', '/').replace(/\/$/, ''); +const isPrettyUrl = requestedPath.startsWith('/20') || /^\/\d{4}-/.test(requestedPath); +const finalCanonicalPath = isPrettyUrl ? requestedPath : Astro.url.pathname; +const finalCanonicalURL = new URL(finalCanonicalPath, Astro.site); + const { title, description, image = "/astro-micro.jpg" } = Astro.props; --- @@ -35,7 +41,7 @@ const { title, description, image = "/astro-micro.jpg" } = Astro.props; - +