summaryrefslogtreecommitdiff
path: root/script.js
diff options
context:
space:
mode:
Diffstat (limited to 'script.js')
-rw-r--r--script.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/script.js b/script.js
new file mode 100644
index 0000000..b37a235
--- /dev/null
+++ b/script.js
@@ -0,0 +1,25 @@
+const routes = {
+ '/': 'page-home',
+ '/blog': 'page-blog',
+ '/about': 'page-about',
+};
+
+function navigate() {
+ const hash = location.hash.replace('#', '') || '/';
+
+ // Hide all pages
+ document.querySelectorAll('.page').forEach(el => el.classList.remove('active'));
+
+ // Update nav
+ document.querySelectorAll('nav a').forEach(a => {
+ const path = a.getAttribute('href').replace('#', '');
+ a.classList.toggle('active', path === hash);
+ });
+
+ // Show matching page, fall back to 404
+ const pageId = routes[hash] || 'page-404';
+ document.getElementById(pageId).classList.add('active');
+}
+
+window.addEventListener('hashchange', navigate);
+navigate(); // run on load