Skip to content

Commit 8329eec

Browse files
authored
Merge pull request #475 from openscript-ch/openscript/issue452
Add 404 page
2 parents 639bd6f + 2c4b59c commit 8329eec

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

.changeset/bold-words-post.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openscript-ch-website": patch
3+
---
4+
5+
Add 404 page

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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
</Shell>
35+
36+
<script>
37+
function register() {
38+
const localeElements = document.querySelectorAll("[data-translation]");
39+
const pathname = window.location.pathname;
40+
const activeElement =
41+
Array.from(localeElements).find(
42+
(el) => el instanceof HTMLElement && pathname.startsWith(`/${el.dataset.translation}/`),
43+
) || document.querySelector('[data-translation="de"]');
44+
45+
if (activeElement instanceof HTMLElement) {
46+
activeElement.classList.add("active");
47+
}
48+
}
49+
50+
register();
51+
document.addEventListener("astro:after-swap", register);
52+
</script>

0 commit comments

Comments
 (0)