import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "./types" import legacyStyle from "./styles/legacyToc.scss" import modernStyle from "./styles/toc.scss" import { classNames } from "../util/lang" // @ts-ignore import script from "./scripts/toc.inline" import { i18n } from "../i18n" import OverflowListFactory from "./OverflowList" import { concatenateResources } from "../util/resources" interface Options { layout: "modern" | "legacy" } const defaultOptions: Options = { layout: "modern", } export default ((opts?: Partial) => { const layout = opts?.layout ?? defaultOptions.layout const { OverflowList, overflowListAfterDOMLoaded } = OverflowListFactory() const TableOfContents: QuartzComponent = ({ fileData, displayClass, cfg, }: QuartzComponentProps) => { if (!fileData.toc) { return null } return (
{fileData.toc.map((tocEntry) => (
  • {tocEntry.text}
  • ))}
    ) } TableOfContents.css = modernStyle TableOfContents.afterDOMLoaded = concatenateResources(script, overflowListAfterDOMLoaded) const LegacyTableOfContents: QuartzComponent = ({ fileData, cfg }: QuartzComponentProps) => { if (!fileData.toc) { return null } return (

    {i18n(cfg.locale).components.tableOfContents.title}

    ) } LegacyTableOfContents.css = legacyStyle return layout === "modern" ? TableOfContents : LegacyTableOfContents }) satisfies QuartzComponentConstructor