2023-06-10 06:06:02 +00:00
|
|
|
import { QuartzComponentProps } from "./types"
|
|
|
|
import style from "./styles/toc.scss"
|
|
|
|
|
2023-06-12 06:26:43 +00:00
|
|
|
export default function TableOfContents({ fileData }: QuartzComponentProps) {
|
2023-06-10 06:06:02 +00:00
|
|
|
if (!fileData.toc) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2023-06-12 06:26:43 +00:00
|
|
|
return <details class="toc" open>
|
|
|
|
<summary><h3>Table of Contents</h3></summary>
|
|
|
|
<ul>
|
|
|
|
{fileData.toc.map(tocEntry => <li key={tocEntry.slug} class={`depth-${tocEntry.depth}`}>
|
|
|
|
<a href={`#${tocEntry.slug}`}>{tocEntry.text}</a>
|
|
|
|
</li>)}
|
|
|
|
</ul>
|
|
|
|
</details>
|
2023-06-10 06:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TableOfContents.css = style
|