// window.addEventListener("popstate", () => {
// //const link = location.pathname.replace(/^.*[\\/]/, ""); // get filename only
// loadContent(location.href)
// })
async function loadContent(url) {
console.log("gonna load", url)
// check exact same url as current
if (url.replace(/\/$/, "") === location.href) {
console.log("do nothing")
return
}
function getBetween(s, l, r) {
return s.substring(s.indexOf(l) + l.length, s.indexOf(r))
}
const resp = await fetch(url)
if (!resp.ok) return
let s = await resp.text()
//console.log(newContent);
//console.log(newContent.split('
', 2))
const content = getBetween(s, "", "")
const title = getBetween(s, "", "")
console.log("got", title)
//let newContent = newContent.split('', 2)[1].split('',1)[0]
//better is to just replace the body content (do a split with a specific separator tag!)
document.body.innerHTML = content
document.title = title
window.scrollTo(0, 0)
}
async function nav(e, aEl) {
// e = e || window.event
// if (!e) return
// let href = aEl.href
// if (href.indexOf(location.origin) === -1) return
// e.preventDefault()
// history.pushState(null, null, href)
// loadContent(href)
}
function toggleThemePreference() {
let theme = localStorage.theme || "light"
const toggled = theme === "dark" ? "light" : "dark"
localStorage.theme = toggled
if (toggled === "dark") {
document.documentElement.classList.add("dark")
} else {
document.documentElement.classList.remove("dark")
}
}