diff --git a/public/app.js b/public/app.js index 5dc1234..36cd5a5 100755 --- a/public/app.js +++ b/public/app.js @@ -1,6 +1,7 @@ const els = { body: document.body, menuBtn: document.getElementById("menuBtn"), + primaryNav: document.getElementById("primaryNav"), sectionSelect: document.getElementById("sectionSelect"), sortSelect: document.getElementById("sortSelect"), searchBox: document.getElementById("searchBox"), @@ -10,6 +11,11 @@ const els = { }; const staticPages = new Set(["about", "contact", "legal"]); +const sectionIcons = { // Optional: Add icons per section (e.g., 'essays': '✍️') + essays: '✍️', + fieldnotes: '📓', + pinned: '📌' +}; let indexData = null; let sidebarOpen = false; @@ -17,22 +23,34 @@ let sidebarOpen = false; async function init() { try { indexData = await (await fetch("index.json")).json(); + populateNav(); populateSections(); wireUI(); renderList(); handleHash(); window.addEventListener("hashchange", handleHash); } catch (e) { - els.viewer.innerHTML = "
Failed to load site data. Please try refreshing.
"; + els.viewer.innerHTML = "Failed to load index data. Please refresh or check connection.
"; } } +function populateNav() { + els.primaryNav.innerHTML = 'Home'; + staticPages.forEach(p => { + els.primaryNav.innerHTML += `${p.charAt(0).toUpperCase() + p.slice(1)}`; + }); + indexData.sections.forEach(s => { + els.primaryNav.innerHTML += `${s.charAt(0).toUpperCase() + s.slice(1)}`; + }); +} + function populateSections() { els.sectionSelect.innerHTML = ""; indexData.sections.forEach(s => { + const icon = sectionIcons[s] ? `${sectionIcons[s]} ` : ''; const opt = document.createElement("option"); opt.value = s; - opt.textContent = s; + opt.textContent = `${icon}${s}`; els.sectionSelect.appendChild(opt); }); } @@ -72,54 +90,59 @@ function renderList() { } async function handleHash() { - els.viewer.innerHTML = ""; // Clear viewer to avoid stale content + els.viewer.innerHTML = ""; const rel = location.hash.replace(/^#\//, ""); if (!rel) return renderDefault(); if (rel.endsWith('/')) { const section = rel.replace(/\/$/, ''); if (staticPages.has(section)) { - renderHTML(section + '/index.html'); + renderIframe(`${section}/index.html`); } else if (indexData.sections.includes(section)) { els.sectionSelect.value = section; renderList(); const sectionPosts = indexData.flat.filter(p => p.path.split('/')[0] === section); if (sectionPosts.length === 0) { - els.viewer.innerHTML = `No posts in this section yet.
`; + els.viewer.innerHTML = `No content in this section yet. Check back soon!
`; } else { const latest = sectionPosts.sort((a, b) => b.mtime - a.mtime)[0]; - location.hash = '#/' + latest.path; // Triggers hashchange to load + location.hash = '#/' + latest.path; } } else { - els.viewer.innerHTML = 'The requested section does not exist.
'; } } else { const file = indexData.flat.find(f => f.path === rel); if (!file) { - els.viewer.innerHTML = 'The requested file could not be located.
'; return; } try { - file.ext === ".md" ? await renderMarkdown(file.path) : renderHTML(file.path); + if (file.ext === ".md") { + await renderMarkdown(file.path); + } else { + renderIframe(file.path); + } } catch (e) { - els.viewer.innerHTML = 'Failed to load the file. Please try another.
'; + els.viewer.innerHTML = 'Unable to load the file. It may be corrupted or inaccessible.
'; } } } async function renderMarkdown(rel) { - const src = await fetch(rel).then(r => { if (!r.ok) throw new Error(); return r.text(); }); + const src = await fetch(rel).then(r => { if (!r.ok) throw new Error('Fetch failed'); return r.text(); }); const html = marked.parse(src); els.viewer.innerHTML = `No content yet. Add files to sections and redeploy!
'; + } } init(); \ No newline at end of file