20 lines
606 B
TypeScript
20 lines
606 B
TypeScript
import type { Heading } from '@/lib/content';
|
|
|
|
export function Toc({ headings }: { headings: Heading[] }) {
|
|
if (headings.length === 0) return null;
|
|
return (
|
|
<nav aria-label="Table of contents" className="text-sm">
|
|
<p className="mb-2 font-semibold">On this page</p>
|
|
<ul className="space-y-1">
|
|
{headings.map((heading) => (
|
|
<li key={heading.id} className={heading.level === 3 ? 'pl-4' : ''}>
|
|
<a href={`#${heading.id}`} className="muted hover:opacity-80">
|
|
{heading.text}
|
|
</a>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</nav>
|
|
);
|
|
}
|