/* Keru website — inject shared nav + footer partials. Usage: data-base is the path prefix from this page to the web root. All links inside the injected partials are resolved against that base. */ (function () { var base = '.'; var scripts = document.querySelectorAll('script[src*="include.js"]'); for (var i = 0; i < scripts.length; i++) { if (scripts[i].dataset.base) base = scripts[i].dataset.base; } var nav = document.querySelector('[data-nav]'); var footer = document.querySelector('[data-footer]'); function fill(el, url) { if (!el) return; fetch(base + '/' + url) .then(function (r) { return r.text(); }) .then(function (t) { // resolve links/asset refs in the partial against base var div = document.createElement('div'); div.innerHTML = t; ['a', 'link', 'script', 'img'].forEach(function (sel) { var nodes = div.querySelectorAll(sel + '[href], ' + sel + '[src]'); for (var j = 0; j < nodes.length; j++) { var n = nodes[j]; var attr = n.hasAttribute('href') ? 'href' : 'src'; var val = n.getAttribute(attr); if (val && val.indexOf('./') === 0) { n.setAttribute(attr, base + '/' + val.replace(/^\.\//, '')); } } }); el.innerHTML = div.innerHTML; }) .catch(function () { /* offline / file:// — nav/footer stay empty */ }); } fill(nav, '_includes/nav.html'); fill(footer, '_includes/footer.html'); })();