Skip to content

Commit f8b31c7

Browse files
committed
Playing with 404s
1 parent 5ab1a24 commit f8b31c7

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

src/components/overrides/Page.astro

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,46 @@ const data = props.entry.data;
99
1010
const html = await Astro.slots.render("default");
1111
12+
if (props.id === "404") {
13+
props.toc = undefined;
14+
}
15+
1216
if (props.toc) {
1317
props.toc.items = await generateTableOfContents(html);
1418
}
1519
1620
if (props.hasSidebar) {
17-
const group = await getSidebar(Astro);
18-
props.sidebar = group.entries;
21+
try {
22+
const group = await getSidebar(Astro);
23+
props.sidebar = group.entries;
1924
20-
if (props.pagination) {
21-
const flattened = flattenSidebar(props.sidebar);
25+
if (props.pagination) {
26+
const flattened = flattenSidebar(props.sidebar);
2227
23-
const idx = flattened.findIndex((entry) => entry.isCurrent);
28+
const idx = flattened.findIndex((entry) => entry.isCurrent);
2429
25-
let prev = flattened[idx - 1];
26-
let next = flattened[idx + 1];
30+
let prev = flattened[idx - 1];
31+
let next = flattened[idx + 1];
2732
28-
if (prev?.attrs["data-group-label"]) {
29-
prev = {
30-
...prev,
31-
label: prev.attrs["data-group-label"],
32-
};
33-
}
33+
if (prev?.attrs["data-group-label"]) {
34+
prev = {
35+
...prev,
36+
label: prev.attrs["data-group-label"],
37+
};
38+
}
3439
35-
if (next?.attrs["data-group-label"]) {
36-
next = {
37-
...next,
38-
label: next.attrs["data-group-label"],
39-
};
40-
}
40+
if (next?.attrs["data-group-label"]) {
41+
next = {
42+
...next,
43+
label: next.attrs["data-group-label"],
44+
};
45+
}
4146
42-
props.pagination.prev = prev;
43-
props.pagination.next = next;
47+
props.pagination.prev = prev;
48+
props.pagination.next = next;
49+
}
50+
} catch {
51+
props.hasSidebar = false;
4452
}
4553
}
4654

src/content/docs/404.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: "404"
3+
template: doc
4+
editUrl: false
5+
hero:
6+
title: "404"
7+
tagline: Page not found. Check the URL or try using the search bar.
8+
---

0 commit comments

Comments
 (0)