fix(404): noindex the error page instead of emitting a canonical to /404/
Deploy / build (push) Successful in 2m59s

A canonical pointing at a URL that does not exist is worse than none. Normal pages
are untouched (canonical still emitted, no robots meta).
This commit is contained in:
hoelee committed 2026-10-16 20:57:20 +08:00
1 parent 874c434576
commit 8619e48271
2 files changed
+6 -1

No files matched your search

+5 -1
View File
@@ -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>{title}</title>
<meta name="description" content={description} />
<link rel="canonical" href={canonical} />
{noindex ? <meta name="robots" content="noindex, follow" /> : <link rel="canonical" href={canonical} />}
<!-- hreflang: this page + its other-language twin -->
{hreflang.map((alt) => (
+1
View File
@@ -15,6 +15,7 @@ const fmt = (d: Date) =>
<BaseLayout
title="404 — Page Not Found — Mr Hoelee"
description="That URL does not exist on this site. Search the posts or browse the archive."
noindex
>
<h1>404 — container exited (code 1)</h1>
<p>