--- import type { MarkdownHeading } from "astro"; import { siteConfig } from "../../config"; import { url } from "../../utils/url-utils"; interface Props { class?: string; headings: MarkdownHeading[]; } let { headings = [] } = Astro.props; let minDepth = 10; for (const heading of headings) { minDepth = Math.min(minDepth, heading.depth); } const className = Astro.props.class; const isPostsRoute = Astro.url.pathname.startsWith(url("/posts/")); const removeTailingHash = (text: string) => { let lastIndexOfHash = text.lastIndexOf("#"); if (lastIndexOfHash !== text.length - 1) { return text; } return text.substring(0, lastIndexOfHash); }; let heading1Count = 1; const maxLevel = siteConfig.toc.depth; --- {isPostsRoute && {headings.filter((heading) => heading.depth < minDepth + maxLevel).map((heading) =>
{heading.depth == minDepth && heading1Count++} {heading.depth == minDepth + 1 &&
} {heading.depth == minDepth + 2 &&
}
{removeTailingHash(heading.text)}
)}
}