From 30a19112216e12d19459474f7308ec57cd8aaf9d Mon Sep 17 00:00:00 2001 From: R-man3000 Date: Fri, 12 Jun 2026 17:00:31 +0300 Subject: site redo --- script.js | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'script.js') diff --git a/script.js b/script.js index b37a235..7b52657 100644 --- a/script.js +++ b/script.js @@ -1,25 +1,17 @@ -const routes = { - '/': 'page-home', - '/blog': 'page-blog', - '/about': 'page-about', -}; +// Fetch navbar +fetch('/nav.html') + .then(r => r.text()) + .then(html => { + document.getElementById('nav').innerHTML = html; -function navigate() { - const hash = location.hash.replace('#', '') || '/'; + // Mark the current page link as active + const current = window.location.pathname; + document.querySelectorAll('nav a').forEach(a => { + if (a.getAttribute('href') === current) { + a.classList.add('active'); + } + }) + }) - // 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 +// Fetch footer +document.getElementById('footer').innerHTML = '© 2026 Luhamus'; -- cgit v1.2.3