/* ─── Dynamic Navigation ─── */ /* Fetches nav items from /api/navigation and renders them */ (function() { 'use strict'; async function loadNavigation() { const navMenu = document.getElementById('navMenu'); if (!navMenu) return; try { const res = await fetch('/api/navigation'); if (!res.ok) throw new Error('Nav API ' + res.status); const items = await res.json(); // Sort by order items.sort((a, b) => (a.order || 0) - (b.order || 0)); // Determine current page for active state const path = window.location.pathname; // Build nav HTML let html = ''; items.forEach(item => { const url = item.url || '/'; const label = (item.label || '').toUpperCase(); // Determine if this link is active let isActive = false; if (url === '/' && (path === '/' || path === '/index.html')) { isActive = true; } else if (url !== '/' && path.startsWith(url)) { isActive = true; } const activeClass = isActive ? ' active' : ''; // Check if it's an anchor link (homepage sections) const isAnchor = url.startsWith('#') || url.startsWith('/#'); const href = isAnchor && path !== '/' ? '/' + url.replace(/^\//, '') : url; html += `