From 8619e48271ef76c0d216561d361dc70a18b62df4 Mon Sep 17 00:00:00 2001 From: hoelee Date: Fri, 16 Oct 2026 20:57:20 +0800 Subject: [PATCH] fix(404): noindex the error page instead of emitting a canonical to /404/ A canonical pointing at a URL that does not exist is worse than none. Normal pages are untouched (canonical still emitted, no robots meta). --- src/layouts/BaseLayout.astro | 6 +++++- src/pages/404.astro | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/layouts/BaseLayout.astro b/src/layouts/BaseLayout.astro index ae54951..fc1114e 100644 --- a/src/layouts/BaseLayout.astro +++ b/src/layouts/BaseLayout.astro @@ -24,6 +24,9 @@ interface Props { tags?: string[]; category?: string; }; + // Error pages: emit noindex and skip the canonical (a canonical pointing at a + // page that does not exist is worse than none). + noindex?: boolean; } const { @@ -35,6 +38,7 @@ const { switchHref, altLocaleUrl, article, + noindex = false, } = Astro.props; const canonical = new URL(Astro.url.pathname, SITE.url).href; @@ -71,7 +75,7 @@ const nav = isZh {title} - + {noindex ? : } {hreflang.map((alt) => ( diff --git a/src/pages/404.astro b/src/pages/404.astro index 1ae4074..63efbac 100644 --- a/src/pages/404.astro +++ b/src/pages/404.astro @@ -15,6 +15,7 @@ const fmt = (d: Date) =>

404 — container exited (code 1)