From 5f9fa6b977fee2ad9026f33b102c6e575189c3c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mark=20Randall=20Havens=20=E2=96=B3=20The=20Empathic=20Tec?= =?UTF-8?q?hnologist=20=E2=9F=81=20Doctor=20Who=2042?= Date: Thu, 16 Oct 2025 17:25:32 -0500 Subject: [PATCH] Create main.js --- main.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 main.js diff --git a/main.js b/main.js new file mode 100644 index 0000000..11d75b5 --- /dev/null +++ b/main.js @@ -0,0 +1,43 @@ +// main.js +// Client-side markdown renderer for "The Fold Within" + +document.addEventListener('DOMContentLoaded', async () => { + const content = document.querySelector('main'); + const postsDir = 'posts/'; + + // Load Markdown renderer + const rendererScript = document.createElement('script'); + rendererScript.src = 'https://cdn.jsdelivr.net/npm/marked/marked.min.js'; + document.head.appendChild(rendererScript); + + rendererScript.onload = () => { + // Attach click handlers to all articles + document.querySelectorAll('article').forEach(article => { + article.addEventListener('click', async () => { + const slug = article.querySelector('h3').textContent.trim() + .toLowerCase().replace(/\s+/g, '-'); + loadPost(slug); + }); + }); + }; + + async function loadPost(slug) { + try { + const res = await fetch(`${postsDir}${slug}.md`); + if (!res.ok) throw new Error('Post not found.'); + const md = await res.text(); + const html = marked.parse(md); + + content.innerHTML = ` +
+ ← Back +
${html}
+
+ `; + + document.getElementById('back').addEventListener('click', () => location.reload()); + } catch (err) { + content.innerHTML = `

⚠️ ${err.message}

`; + } + } +}); \ No newline at end of file