From 13b23ace3d4914906638c9082cae739f432da6fc Mon Sep 17 00:00:00 2001 From: Wesley Ray Date: Wed, 15 Jul 2026 14:54:04 -0400 Subject: [PATCH] Sidebar nav: full garden tree on every page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - buildNavTree: every non-draft page nested by vault folder; folders link to their (real or synthetic) index page and take its title when set - NavTree component: recursive details/summary tree, no JS — folders on the current path render open, current page gets aria-current styling - layout: sticky left sidebar >=72rem, flows after the footer as a site index on narrow screens Co-Authored-By: Claude Opus 4.8 --- src/components/NavTree.astro | 38 +++++++++++ src/layouts/Base.astro | 125 ++++++++++++++++++++++++++++++----- src/lib/nav.mjs | 55 +++++++++++++++ 3 files changed, 202 insertions(+), 16 deletions(-) create mode 100644 src/components/NavTree.astro create mode 100644 src/lib/nav.mjs diff --git a/src/components/NavTree.astro b/src/components/NavTree.astro new file mode 100644 index 0000000..4ed7145 --- /dev/null +++ b/src/components/NavTree.astro @@ -0,0 +1,38 @@ +--- +interface Props { + nodes: any[]; + currentPath: string; +} +const { nodes, currentPath } = Astro.props; +// build-time pathnames may carry .html / index.html suffixes — normalize +const norm = decodeURIComponent(currentPath) + .replace(/index\.html$/, '') + .replace(/\.html$/, ''); +const here = (u: string) => norm === u || norm === u.replace(/\/$/, ''); +const under = (u: string) => norm.startsWith(u); +--- + + diff --git a/src/layouts/Base.astro b/src/layouts/Base.astro index 96c00a4..b5f6dbc 100644 --- a/src/layouts/Base.astro +++ b/src/layouts/Base.astro @@ -1,5 +1,8 @@ --- import 'katex/dist/katex.min.css'; +import { getCollection } from 'astro:content'; +import { buildNavTree } from '../lib/nav.mjs'; +import NavTree from '../components/NavTree.astro'; interface Props { title: string; @@ -7,6 +10,7 @@ interface Props { } const { title, description } = Astro.props; const isHome = Astro.url.pathname === '/'; +const navTree = buildNavTree(await getCollection('garden')); --- @@ -22,19 +26,27 @@ const isHome = Astro.url.pathname === '/'; src="https://plausible.io/js/script.js"> -
- {!isHome && } -
-
- -
- +
+
+
+ {!isHome && } +
+
+ +
+ +
+ +