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"> -