2023-06-12 09:46:38 +03:00
|
|
|
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
2023-06-10 09:06:02 +03:00
|
|
|
import style from "./styles/toc.scss"
|
|
|
|
|
|
|
|
|
2023-06-13 08:41:42 +03:00
|
|
|
interface Options {
|
|
|
|
layout: 'modern' | 'quartz-3'
|
|
|
|
}
|
|
|
|
|
|
|
|
const defaultOptions: Options = {
|
|
|
|
layout: 'quartz-3'
|
2023-06-10 09:06:02 +03:00
|
|
|
}
|
|
|
|
|
2023-06-13 08:41:42 +03:00
|
|
|
export default ((opts?: Partial<Options>) => {
|
|
|
|
const layout = opts?.layout ?? defaultOptions.layout
|
|
|
|
if (layout === "modern") {
|
|
|
|
return function() {
|
|
|
|
return null // TODO (make this look like nextra)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
function TableOfContents({ fileData }: QuartzComponentProps) {
|
|
|
|
if (!fileData.toc) {
|
|
|
|
return null
|
|
|
|
}
|
2023-06-12 09:46:38 +03:00
|
|
|
|
2023-06-13 08:41:42 +03: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>
|
|
|
|
}
|
|
|
|
|
|
|
|
TableOfContents.css = style
|
|
|
|
return TableOfContents
|
|
|
|
}
|
|
|
|
}) satisfies QuartzComponentConstructor
|