chore: fixes

This commit is contained in:
MattTheTekie 2026-04-23 17:55:10 -04:00
commit 3936821c5d

View file

@ -18,33 +18,47 @@
</div>
<!-- JS LOADER -->
<script>
window.addEventListener("load", () => {
const target = document.getElementById("content");
console.log("target:", target);
function loadPage(event, page) {
event.preventDefault();
if (!target) return;
fetch(page)
.then(response => response.text())
.then(html => {
fetch("/about.html")
.then(res => {
console.log("status:", res.status);
return res.text();
})
.then(html => {
const temp = document.createElement("div");
temp.innerHTML = html;
// Parse the full HTML document safely
const parser = new DOMParser();
const doc = parser.parseFromString(html, "text/html");
const section = temp.querySelector("#aboutSection");
// Extract ONLY body content
const newContent = doc.body.innerHTML;
target.innerHTML = section
? section.innerHTML
: "<h2>About</h2><p>Failed to load content</p>";
})
.catch(err => {
console.error(err);
target.innerHTML = "<h2>About</h2><p>Error loading page</p>";
});
});
// Replace your content area
const container = document.getElementById("content");
container.innerHTML = newContent;
// OPTIONAL: re-run scripts inside loaded page
const scripts = container.querySelectorAll("script");
scripts.forEach(oldScript => {
const newScript = document.createElement("script");
// copy inline script or src script
if (oldScript.src) {
newScript.src = oldScript.src;
} else {
newScript.textContent = oldScript.textContent;
}
oldScript.remove();
document.body.appendChild(newScript);
});
})
.catch(err => {
console.error(err);
document.getElementById("content").innerHTML =
"<p>Error loading page.</p>";
});
}
</script>
</body>
</html>