added 404 page

This commit is contained in:
2026-10-09 19:57:06 -07:00
parent 6cdbdd6351
commit d38fcbe017
7 changed files with 139 additions and 5 deletions

View File

@@ -455,7 +455,12 @@ function resolveRoute(pathname) {
}
}
}
return { tab: SITE_TREE[0], group: SITE_TREE[0].groups[0], item: SITE_TREE[0].groups[0].items[0] };
return {
is404: true,
tab: SITE_TREE[0],
group: { title: "Error" },
item: { title: "404 Not Found", path: path }
};
}
function renderNavTabs(currentTab) {
@@ -837,6 +842,47 @@ function loadPage() {
document.title = route.item.title + " — Vyla";
var contentEl = document.getElementById("main-content");
document.body.classList.remove("is-404");
var route = resolveRoute(window.location.pathname);
renderNavTabs(route.tab);
renderSidebar(route.tab, route.item);
document.title = route.item.title + " — Vyla";
var contentEl = document.getElementById("main-content");
if (route.is404) {
document.body.classList.add("is-404");
document.title = "404 - Page Not Found — Vyla";
if (contentEl) {
contentEl.classList.remove("content-animate");
contentEl.innerHTML =
'<div class="error-container">' +
' <div class="error-code">404</div>' +
' <div class="error-title">PAGE NOT FOUND</div>' +
' <p class="error-desc">But if you don\'t change your direction, and if you keep looking, you may end up where you are heading.</p>' +
' <a href="/" class="btn-home">Take me home</a>' +
'</div>';
var tocList = document.getElementById("toc-list");
if (tocList) tocList.innerHTML = "";
var prevBtn = document.getElementById("footer-prev");
var nextBtn = document.getElementById("footer-next");
if (prevBtn) prevBtn.classList.add("hidden");
if (nextBtn) nextBtn.classList.add("hidden");
window.scrollTo(0, 0);
}
var sidebar = document.getElementById("sidebar");
if (sidebar && sidebar.classList.contains("open")) {
sidebar.classList.remove("open");
document.body.classList.remove("nav-open");
}
return;
}
if (contentEl) {
contentEl.classList.remove("content-animate");
contentEl.innerHTML =
@@ -854,7 +900,8 @@ function loadPage() {
fetch(route.item.file)
.then(function (res) {
if (!res.ok) throw new Error("Not found");
var ctype = res.headers.get("content-type") || "";
if (!res.ok || ctype.indexOf("text/html") !== -1) throw new Error("Not found");
return res.text();
})
.then(function (md) {