diff options
| author | R-man3000 <rasmus.luha@gmail.com> | 2026-06-12 14:35:35 +0300 |
|---|---|---|
| committer | R-man3000 <rasmus.luha@gmail.com> | 2026-06-12 14:35:35 +0300 |
| commit | 0cc9d2b094c35adfe6d3b548d7d40219cc611d32 (patch) | |
| tree | 4d993931711eb395beedf4ce3b3879fab50998d5 /script.js | |
| parent | 0b93b2583fa57bcfa8a70ebed3f90e5e78d76bfe (diff) | |
barebones site start
Diffstat (limited to 'script.js')
| -rw-r--r-- | script.js | 25 |
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 |
