Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
1.1 kB ยท 31 lines
TypeScript
1234567891011121314151617181920212223242526272829303132import { slugify } from "./mdx-components/heading";
export type TocItem = { depth: 2 | 3; text: string; slug: string };
// Extract h2/h3 headings from raw MDX for the table of contents. Slugs are// produced with the same `slugify` that `createHeading` uses at render time, so// the TOC links resolve to the real heading ids. Fenced code blocks are skipped// so `## comment` lines inside code don't leak into the TOC. Inline-code// backticks are dropped to match the label `createHeading` renders.export function extractHeadings(source: string): TocItem[] { const items: TocItem[] = []; let inFence = false;
for (const line of source.split("\n")) { const fence = line.match(/^\s*(```|~~~)/); if (fence) { inFence = !inFence; continue; } if (inFence) continue;
const heading = line.match(/^(#{2,3})\s+(.+?)\s*#*\s*$/); if (!heading) continue;
const depth = heading[1].length as 2 | 3; const text = heading[2].trim().replace(/`/g, ""); items.push({ depth, text, slug: slugify(text) }); }
return items;}