Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit 0468b71

Browse files
committed
Make navbar automatically fill in games
1 parent b632b4e commit 0468b71

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

src/lib/navbar.svelte

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
const isActive = (tabName: string) => {
1010
return tabName === pageName ? "active" : "";
1111
};
12+
13+
import type { ComponentType } from "svelte";
14+
15+
const modules = import.meta.glob<Object>("../routes/games/*/+page.svelte", {
16+
eager: true,
17+
});
1218
</script>
1319

1420
<ul id="navbar">
@@ -18,12 +24,22 @@
1824
<!-- margin left auto to move to the right, also moves all children after to the right -->
1925
<li style="margin-left: auto;">
2026
<Menu>
21-
<a class={isActive("Games")} href="/" id="games" slot="toggle"
27+
<a class={isActive("Games")} href="/games" id="games" slot="toggle"
2228
>Games</a
2329
>
24-
<MenuItem class="menu-item"
25-
><a href="/FarmingDragons">Farming Dragons</a></MenuItem
26-
>
30+
31+
{#each Object.entries(modules) as [_path, module]}
32+
<MenuItem class="menu-item">
33+
<a
34+
href="/games/{_path
35+
.replace('../routes/games/', '')
36+
.replace('/+page.svelte', '')}"
37+
>{_path
38+
.replace("../routes/games/", "")
39+
.replace("/+page.svelte", "")}</a
40+
>
41+
</MenuItem>;
42+
{/each}
2743
</Menu>
2844
</li>
2945
<li class="navbar-item {isActive('About')}">

src/routes/games/+page.svelte

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import "$lib/global.css";
3+
import Navbar from "$lib/navbar.svelte";
4+
</script>
5+
6+
<navbar-component pageName="Games"></navbar-component>
7+
8+
<h1>GAMES!!</h1>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import "$lib/global.css";
3+
import Navbar from "$lib/navbar.svelte";
4+
</script>
5+
6+
<navbar-component pageName="Games"></navbar-component>
7+
8+
<h1>EAC Go</h1>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import "$lib/global.css";
3+
import Navbar from "$lib/navbar.svelte";
4+
</script>
5+
6+
<navbar-component pageName="Games"></navbar-component>
7+
8+
<h1>Farming dragons!!</h1>

0 commit comments

Comments
 (0)