Update app.js

This commit is contained in:
Mark Randall Havens △ The Empathic Technologist ⟁ Doctor Who 42 2025-11-09 00:10:38 -06:00 committed by GitHub
parent 033d761f5c
commit 130ce78360
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -16,11 +16,13 @@ const els = {
let indexData = null; let indexData = null;
let sidebarOpen = false; let sidebarOpen = false;
let currentParentSection = null; let currentParent = null;
let indexFiles = null; // Cached
async function init() { async function init() {
try { try {
indexData = await (await fetch("index.json")).json(); indexData = await (await fetch("index.json")).json();
indexFiles = indexData.flat.filter(f => f.isIndex); // Cache
populateNav(); populateNav();
populateSections(); populateSections();
populateTags(); populateTags();
@ -141,7 +143,7 @@ function loadDefaultForSection(section) {
location.hash = `#/${pinned.path}`; location.hash = `#/${pinned.path}`;
} }
// HORIZON LAYER: Emergent Sub-Navigation // NESTED HORIZON: Deep-Aware Sub-Navigation
function renderSubNav(parent) { function renderSubNav(parent) {
const subnav = els.subNav; const subnav = els.subNav;
subnav.innerHTML = ""; subnav.innerHTML = "";
@ -162,33 +164,36 @@ function renderSubNav(parent) {
}); });
} }
// CORE FIX: RENDER INDEX AT CURRENT LEVEL
async function handleHash() { async function handleHash() {
els.viewer.innerHTML = ""; els.viewer.innerHTML = "";
const rel = location.hash.replace(/^#\//, ""); const rel = location.hash.replace(/^#\//, "");
const parts = rel.split("/").filter(Boolean); // e.g., ["about"], ["about", "Mark"] const parts = rel.split("/").filter(Boolean); // e.g., ["about", "Mark"]
let parentSection = null; // Determine current depth parent for subnav
if (parts.length >= 1) { const currentParentPath = parts.slice(0, -1).join("/") || parts[0] || null;
parentSection = parts[0];
if (currentParentPath !== currentParent) {
currentParent = currentParentPath;
renderSubNav(currentParent);
} }
// Update subnav if parent changed // Sync sidebar section to top-level
if (parentSection !== currentParentSection) { const topSection = parts[0] || null;
currentParentSection = parentSection; if (topSection && indexData.sections.includes(topSection)) {
renderSubNav(parentSection); els.sectionSelect.value = topSection;
renderList();
} }
if (!rel) return renderDefault(); if (!rel) return renderDefault();
// CASE: Trailing slash → render index at *current* level // CASE: Trailing slash → render index at *current* level
if (rel.endsWith('/')) { if (rel.endsWith('/')) {
const currentPath = parts.join("/"); // "about" or "about/Mark" const currentPath = parts.join("/");
const expectedIndexPath = currentPath + "/";
const indexFile = indexData.flat.find(f => const indexFile = indexFiles.find(f => {
f.path.startsWith(expectedIndexPath) && f.isIndex const dir = f.path.split("/").slice(0, -1).join("/");
); return dir === currentPath;
});
if (indexFile) { if (indexFile) {
try { try {
@ -224,10 +229,14 @@ async function handleHash() {
els.viewer.innerHTML = `<h1>${currentPath.split("/").pop()}</h1><p>No content yet.</p>`; els.viewer.innerHTML = `<h1>${currentPath.split("/").pop()}</h1><p>No content yet.</p>`;
} }
} else { } else {
// No index → show list of children or fallback // No index → show children or fallback
els.sectionSelect.value = parentSection; if (topSection) {
renderList(); els.sectionSelect.value = topSection;
loadDefaultForSection(parentSection); renderList();
loadDefaultForSection(topSection);
} else {
els.viewer.innerHTML = `<h1>${currentPath.split("/").pop()}</h1><p>No content yet.</p>`;
}
} }
} }
// CASE: Direct file // CASE: Direct file