import * as React from 'react'; import { TOCHeading } from '../../module'; import { Link } from 'gatsby'; import { useActiveHash } from '../../hooks/useActiveHash'; import { useMemo } from 'react'; // lol this file is basically idential to the sidebar file... should consolidate const TableOfContentsBlock = ({ tableOfContents, }: { tableOfContents: TOCHeading[]; }) => { let links = []; let curDepth = -1; let indentIdx = 0; let indent = ['0', '1.5rem', '3rem', '4.5rem']; tableOfContents.forEach((heading, idx) => { if (curDepth === -1) curDepth = heading.depth; if (heading.depth > curDepth) { indentIdx++; } else if (heading.depth < curDepth) { indentIdx = Math.max(0, indentIdx - 1); } curDepth = heading.depth; links.push( heading.depth) || (idx !== tableOfContents.length - 1 && tableOfContents[idx + 1].depth > heading.depth)) ? '1rem' : indentIdx === 0 ? '0.5rem' : 0, }} > {heading.value} ); }); return (

Table of Contents

{links}
); }; export default TableOfContentsBlock;