--- import type { MarkdownHeading } from 'astro'; type Props = { headings: MarkdownHeading[]; }; type HeadingWithSubheadings = MarkdownHeading & { subheadings: MarkdownHeading[]; }; const { headings } = Astro.props; const grouppedHeadings = headings.reduce((array, heading) => { if (heading.depth === 2) { array.push({ ...heading, subheadings: [] }); } else if (heading.depth === 3) { array.at(-1)?.subheadings.push(heading); } return array; }, [] as HeadingWithSubheadings[]); ---