Update app.js
This commit is contained in:
parent
f26a3dc19e
commit
c64790f2e7
1 changed files with 16 additions and 12 deletions
|
|
@ -33,7 +33,6 @@ async function init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TOP NAV: Only real section folders with index.*
|
|
||||||
function populateNav() {
|
function populateNav() {
|
||||||
els.primaryNav.innerHTML = '<a href="#/">Home</a>';
|
els.primaryNav.innerHTML = '<a href="#/">Home</a>';
|
||||||
const navSections = [...new Set(
|
const navSections = [...new Set(
|
||||||
|
|
@ -46,7 +45,6 @@ function populateNav() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// DROPDOWN: Only sections with NON-index files
|
|
||||||
function populateSections() {
|
function populateSections() {
|
||||||
els.sectionSelect.innerHTML = '<option value="all">All Sections</option>';
|
els.sectionSelect.innerHTML = '<option value="all">All Sections</option>';
|
||||||
indexData.sections.forEach(s => {
|
indexData.sections.forEach(s => {
|
||||||
|
|
@ -167,7 +165,7 @@ function renderSubNav(parent) {
|
||||||
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);
|
const parts = rel.split("/").filter(Boolean); // ["about", "Mark"]
|
||||||
|
|
||||||
let parentSection = null;
|
let parentSection = null;
|
||||||
if (parts.length >= 1) {
|
if (parts.length >= 1) {
|
||||||
|
|
@ -182,17 +180,20 @@ async function handleHash() {
|
||||||
|
|
||||||
if (!rel) return renderDefault();
|
if (!rel) return renderDefault();
|
||||||
|
|
||||||
|
// CASE 1: Deep section with trailing slash → e.g., #about/Mark/
|
||||||
if (rel.endsWith('/')) {
|
if (rel.endsWith('/')) {
|
||||||
const section = parts[0];
|
const fullPath = parts.join("/"); // "about/Mark"
|
||||||
const indexFile = indexData.flat.find(f =>
|
const expectedIndexPath = fullPath + "/"; // "about/Mark/"
|
||||||
f.path.startsWith(section + "/") && f.isIndex
|
|
||||||
|
const indexFile = indexData.flat.find(f =>
|
||||||
|
f.path.startsWith(expectedIndexPath) && f.isIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
if (indexFile) {
|
if (indexFile) {
|
||||||
try {
|
try {
|
||||||
if (indexFile.ext === ".md") {
|
if (indexFile.ext === ".md") {
|
||||||
const src = await fetch(indexFile.path).then(r => r.ok ? r.text() : "");
|
const src = await fetch(indexFile.path).then(r => r.ok ? r.text() : "");
|
||||||
const html = marked.parse(src || `# ${section}\n\nNo content yet.`);
|
const html = marked.parse(src || `# ${fullPath.split("/").pop()}\n\nNo content yet.`);
|
||||||
els.viewer.innerHTML = `<article class="markdown">${html}</article>`;
|
els.viewer.innerHTML = `<article class="markdown">${html}</article>`;
|
||||||
} else {
|
} else {
|
||||||
const iframe = document.createElement("iframe");
|
const iframe = document.createElement("iframe");
|
||||||
|
|
@ -209,7 +210,7 @@ async function handleHash() {
|
||||||
if (!hasContent) {
|
if (!hasContent) {
|
||||||
doc.body.innerHTML = `
|
doc.body.innerHTML = `
|
||||||
<div style="text-align:center;padding:4rem;font-family:Inter,sans-serif;">
|
<div style="text-align:center;padding:4rem;font-family:Inter,sans-serif;">
|
||||||
<h1 style="color:#e6e3d7;">${section}</h1>
|
<h1 style="color:#e6e3d7;">${fullPath.split("/").pop()}</h1>
|
||||||
<p style="color:#888;">No content yet.</p>
|
<p style="color:#888;">No content yet.</p>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
@ -219,14 +220,17 @@ async function handleHash() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
els.viewer.innerHTML = `<h1>${section}</h1><p>No content yet.</p>`;
|
els.viewer.innerHTML = `<h1>${fullPath.split("/").pop()}</h1><p>No content yet.</p>`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
els.sectionSelect.value = section;
|
// Fallback: treat as section list
|
||||||
|
els.sectionSelect.value = parentSection;
|
||||||
renderList();
|
renderList();
|
||||||
loadDefaultForSection(section);
|
loadDefaultForSection(parentSection);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
// CASE 2: Direct file → e.g., #about/Mark/bio.md
|
||||||
|
else {
|
||||||
const file = indexData.flat.find(f => f.path === rel);
|
const file = indexData.flat.find(f => f.path === rel);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
els.viewer.innerHTML = "<h1>404</h1><p>Not found.</p>";
|
els.viewer.innerHTML = "<h1>404</h1><p>Not found.</p>";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue