aboutsummaryrefslogtreecommitdiffstats
path: root/assets/js/includes.js
diff options
context:
space:
mode:
authorsillylaird <sillyfanboy@gmail.com>2026-09-03 00:33:59 +0000
committersillylaird <sillyfanboy@gmail.com>2026-09-03 00:33:59 +0000
commit898b52edcb47bcb3e9d6106e74ca73e74ea01e70 (patch)
tree85c6ee5ad58b860144551184d4cf86b560c62b91 /assets/js/includes.js
downloadwww-main.tar.gz
www-main.zip
import live www.sillylaird.ca webrootHEADmain
Diffstat (limited to '')
-rw-r--r--assets/js/includes.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/assets/js/includes.js b/assets/js/includes.js
new file mode 100644
index 0000000..13a7933
--- /dev/null
+++ b/assets/js/includes.js
@@ -0,0 +1,33 @@
+(async function () {
+ async function loadInto(selector, url) {
+ const mount = document.querySelector(selector);
+ if (!mount) return;
+
+ try {
+ const res = await fetch(url);
+ if (!res.ok) throw new Error("HTTP " + res.status);
+ const html = await res.text();
+ mount.innerHTML = html;
+ } catch (e) {
+ // Fail open: if includes fail, keep page usable.
+ // Intentionally no console noise.
+ }
+ }
+
+ // Pages opt-in by including: <div data-include="header"></div>
+ // and/or <div data-include="footer"></div>
+ await Promise.all([
+ loadInto('[data-include="head-meta"]', "/partials/head-meta.html"),
+ loadInto('[data-include="header"]', "/partials/header.html"),
+ loadInto('[data-include="footer"]', "/partials/footer.html"),
+ ]);
+
+ // If a page uses includes, it likely removed the built-in header/footer.
+ // Re-run site.js behaviors after injection.
+ if (document.querySelector('[data-include="header"], [data-include="footer"]')) {
+ const s = document.createElement("script");
+ s.src = "/assets/js/site.js";
+ s.defer = true;
+ document.head.appendChild(s);
+ }
+})();