Skip to content

Commit 3a92ac7

Browse files
committed
Add 404 page
Fixes #452
1 parent 0d4d573 commit 3a92ac7

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

src/layouts/groups/Contact.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const locale = currentLocale.get();
2121
<Email />
2222
</li>
2323
{
24-
withoutLanguageSwitcher ? null : (
24+
withoutLanguageSwitcher || !translations ? null : (
2525
<li>
2626
<LanguageSwitcher locale={locale} translations={translations} />
2727
</li>

src/pages/404.astro

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
import Button from "../components/Button.astro";
3+
import Shell from "../layouts/Shell.astro";
4+
import Article from "../layouts/templates/Article.astro";
5+
---
6+
7+
<style>
8+
[data-translation] {
9+
display: none;
10+
}
11+
12+
.active[data-translation] {
13+
display: block;
14+
}
15+
</style>
16+
17+
<Shell>
18+
<div data-translation="en">
19+
<Article title="Page not found">
20+
<section>
21+
<p>Sorry, the page you are looking for does not exist.</p>
22+
<Button href="/en" withArrow>Go to home page</Button>
23+
</section>
24+
</Article>
25+
</div>
26+
<div data-translation="de">
27+
<Article title="Seite nicht gefunden">
28+
<section>
29+
<p>Entschuldigung, die von Ihnen gesuchte Seite existiert nicht.</p>
30+
<Button href="/" withArrow>Startseite aufrufen</Button>
31+
</section>
32+
</Article>
33+
</div>
34+
35+
<script>
36+
function register() {
37+
const localeElements = document.querySelectorAll("[data-translation]");
38+
39+
for (const element of localeElements) {
40+
if (!(element instanceof HTMLElement)) continue;
41+
const { translation } = element.dataset;
42+
if (!translation) continue;
43+
44+
if (window.location.pathname.startsWith(`/${translation}/`)) {
45+
element.classList.add("active");
46+
break;
47+
}
48+
}
49+
50+
if (!Array.from(localeElements).some((el) => el instanceof HTMLElement && el.classList.contains("active"))) {
51+
const defaultElement = document.querySelector(`[data-translation="de"]`);
52+
if (defaultElement instanceof HTMLElement) {
53+
defaultElement.classList.add("active");
54+
}
55+
}
56+
}
57+
58+
register();
59+
document.addEventListener("astro:after-swap", register);
60+
</script>
61+
</Shell>

0 commit comments

Comments
 (0)