migrate website from KeruOS web to its own repo
Deploy website to GitHub Pages / deploy (push) Failing after 3s
Deploy website to GitHub Pages / deploy (push) Failing after 3s
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/* Keru website — inject shared nav + footer partials.
|
||||
Usage:
|
||||
<nav data-nav></nav>
|
||||
<footer data-footer></footer>
|
||||
<script src="assets/js/include.js" data-base="."></script>
|
||||
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');
|
||||
})();
|
||||
Reference in New Issue
Block a user