public_notes/quartz/components/TableOfContents.tsx

22 lines
614 B
TypeScript
Raw Normal View History

2023-06-12 15:46:38 +09:00
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
2023-06-10 15:06:02 +09:00
import style from "./styles/toc.scss"
2023-06-12 15:46:38 +09:00
function TableOfContents({ fileData }: QuartzComponentProps) {
2023-06-10 15:06:02 +09:00
if (!fileData.toc) {
return null
}
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 15:06:02 +09:00
}
TableOfContents.css = style
2023-06-12 15:46:38 +09:00
export default (() => TableOfContents) satisfies QuartzComponentConstructor