---
import { type Hierarchy } from "../lib/hierarchy.ts";
import { makeHierarchy } from '../lib/hierarchy';
import { getCollection } from 'astro:content';
interface Props {
prefix: string;
hierarchy?: Hierarchy;
}
const { prefix, hierarchy: maybeHierarchy} = Astro.props;
const notes = await getCollection('notes');
const hierarchy = maybeHierarchy ?? makeHierarchy(notes.map(note => [note.id, note.data.title]));
const pathname = Astro.url.pathname.replace(import.meta.env.BASE_URL, '/');
---
{
Object.entries(hierarchy).map(([leader, node]) => {
const notePath = `${prefix}/${leader}`;
const isActive = pathname === notePath;
const linkClasses = isActive ? "active" : "";
if (node.children) {
return (
{ node.id
? {node.title || leader}
: {node.title || leader}
}