document.addEventListener('DOMContentLoaded', function() { // Get current page path const currentPath = window.location.pathname; const isInPagesDirectory = currentPath.includes('/pages/'); // Handle paths based on directory const navLinks = document.querySelectorAll('#mainNav a'); navLinks.forEach(link => { // Get href attribute let href = link.getAttribute('href'); // Fix paths if in pages directory if (isInPagesDirectory && href.startsWith('index.html')) { link.setAttribute('href', '../' + href); } else if (isInPagesDirectory && href.startsWith('#')) { link.setAttribute('href', '../index.html' + href); } else if (!isInPagesDirectory && href.startsWith('pages/')) { // No change needed for root directory links to pages } // Set active class based on current page if ((currentPath.endsWith('/index.html') || currentPath.endsWith('/')) && href === 'index.html') { link.classList.add('active'); } else if (currentPath.includes(href) && href !== 'index.html') { link.classList.add('active'); } }); });