Skip to content

Commit 73f4168

Browse files
committed
[Docs Site] Make per-product 404 pages and link to SERP/llms.txt
1 parent d4cce74 commit 73f4168

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

astro.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export default defineConfig({
161161
headingLinks: false,
162162
},
163163
routeMiddleware: "./src/plugins/starlight/route-data.ts",
164+
disable404Route: true,
164165
}),
165166
liveCode({}),
166167
icon(),

src/components/404.astro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<div class="flex flex-col items-center justify-center md:py-28">
2+
<h1>404</h1>
3+
<p>
4+
Check the URL, try using our <a id="404-search-link" href="/search/"
5+
>search</a
6+
> or try our LLM-friendly
7+
<a href="/llms.txt"> llms.txt directory</a>.
8+
</p>
9+
</div>
10+
11+
<script>
12+
const { pathname } = window.location;
13+
14+
const anchor = document.getElementById("404-search-link");
15+
16+
if (anchor) {
17+
const pretty = pathname.replaceAll("/", " ").replaceAll("-", " ").trim();
18+
19+
anchor.setAttribute("href", `/search/?q=${encodeURIComponent(pretty)}`);
20+
}
21+
</script>

src/pages/404.astro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
import StarlightPage, {
3+
type StarlightPageProps,
4+
} from "@astrojs/starlight/components/StarlightPage.astro";
5+
import FourOhFour from "~/components/404.astro";
6+
7+
const props = {
8+
frontmatter: {
9+
title: "404 - Page Not Found",
10+
template: "splash",
11+
editUrl: false,
12+
feedback: false,
13+
},
14+
hideTitle: true,
15+
hideBreadcrumbs: true,
16+
} as StarlightPageProps;
17+
---
18+
19+
<StarlightPage {...props}>
20+
<FourOhFour />
21+
</StarlightPage>

src/pages/[product]/404.astro

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
import StarlightPage, {
3+
type StarlightPageProps,
4+
} from "@astrojs/starlight/components/StarlightPage.astro";
5+
import type { GetStaticPaths } from "astro";
6+
import { getCollection } from "astro:content";
7+
8+
import FourOhFour from "~/components/404.astro";
9+
10+
export const getStaticPaths = (async () => {
11+
const sections = await getCollection("docs", (e) => {
12+
return e.id.split("/").length === 1;
13+
});
14+
15+
return sections.map((section) => {
16+
return {
17+
params: {
18+
product: section.id,
19+
},
20+
};
21+
});
22+
}) satisfies GetStaticPaths;
23+
24+
const props = {
25+
frontmatter: {
26+
title: "404 - Page Not Found",
27+
tableOfContents: false,
28+
editUrl: false,
29+
feedback: false,
30+
},
31+
hideTitle: true,
32+
hideBreadcrumbs: true,
33+
} as StarlightPageProps;
34+
---
35+
36+
<StarlightPage {...props}>
37+
<FourOhFour />
38+
</StarlightPage>

0 commit comments

Comments
 (0)