@devries-cameron20 / composio Mirror · read-only / commits / 029b904f9
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 22, 08:15 UTC

fix: extract headings from raw content for fragment validation

data.toc is unavailable when running outside the Next.js runtime (via bun scripts), so fragment links were all flagged as invalid. Parse headings from raw markdown content instead, with a fallback chain: data.toc -> getText('raw') -> readFile. Also adds bunfig.toml with fumadocs-mdx bun preload plugin (recommended by fumadocs docs for running scripts outside Next.js). Reduces false positives from 134 errors to 90 real broken links. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Sushmithamallesh committed Feb 17, 2026 at 19:45 UTC 029b904f9427a40fa40c29dc42ca539e5c9f9be1
3 files changed +83 -23
docs/bunfig.toml new
+1
@@ -0,0 +1 @@
1 +preload = ["./scripts/preload.ts"]
docs/scripts/preload.ts new
+3
@@ -0,0 +1,3 @@
1 +import { createMdxPlugin } from 'fumadocs-mdx/bun';
2 +
3 +Bun.plugin(createMdxPlugin());
docs/scripts/validate-links.ts
+79 -23
@@ -6,7 +6,6 @@ import {
6 scanURLs,
7 validateFiles,
8 } from 'next-validate-link';
9 -import type { InferPageType } from 'fumadocs-core/source';
9 import {
10 source,
11 referenceSource,
@@ -20,27 +19,89 @@ type AnySource =
19 | typeof cookbooksSource
20 | typeof toolkitsSource;
21
22 +type PageOf = ReturnType<AnySource['getPages']>[number];
23 +
24 +/**
25 + * Slugify a heading the same way rehype-slug does.
26 + */
27 +function slugify(text: string): string {
28 + return text
29 + .toLowerCase()
30 + .replace(/[^\w\s-]/g, '')
31 + .replace(/[\s]+/g, '-')
32 + .replace(/-+/g, '-')
33 + .replace(/^-|-$/g, '');
34 +}
35 +
36 +/**
37 + * Extract heading anchors from raw MDX/markdown content.
38 + * Falls back to this when data.toc is unavailable (outside Next.js runtime).
39 + */
40 +function extractHeadingsFromContent(content: string): string[] {
41 + const headings: string[] = [];
42 + for (const line of content.split('\n')) {
43 + const match = line.match(/^#{1,6}\s+(.+)$/);
44 + if (match) {
45 + headings.push(slugify(match[1]));
46 + }
47 + }
48 + return headings;
49 +}
50 +
51 +/**
52 + * Get headings for a page, trying data.toc first then falling back to raw content parsing.
53 + */
54 +async function getHeadingsForPage(page: PageOf): Promise<string[]> {
55 + if (page.data.toc?.length) {
56 + return page.data.toc.map((item: { url: string }) => item.url.slice(1));
57 + }
58 + if ('getText' in page.data) {
59 + try {
60 + const content = await (page.data as { getText: (mode: string) => Promise<string> }).getText('raw');
61 + return extractHeadingsFromContent(content);
62 + } catch {
63 + // fall through
64 + }
65 + }
66 + if (page.absolutePath) {
67 + try {
68 + const content = await readFile(page.absolutePath, 'utf-8');
69 + return extractHeadingsFromContent(content);
70 + } catch {
71 + // fall through
72 + }
73 + }
74 + return [];
75 +}
76 +
77 +/**
78 + * Build populate entries for a source, resolving headings asynchronously.
79 + */
80 +async function buildPopulateEntries(src: AnySource) {
81 + return Promise.all(
82 + src.getPages().map(async (page) => ({
83 + value: { slug: page.slugs },
84 + hashes: await getHeadingsForPage(page),
85 + })),
86 + );
87 +}
88 +
89 async function checkLinks() {
90 + const [docsEntries, refEntries, cookbookEntries, toolkitEntries] = await Promise.all([
91 + buildPopulateEntries(source),
92 + buildPopulateEntries(referenceSource),
93 + buildPopulateEntries(cookbooksSource),
94 + buildPopulateEntries(toolkitsSource),
95 + ]);
96 +
97 const scanned = await scanURLs({
98 preset: 'next',
99 populate: {
27 - // Dynamic routes (keys must include (home) route group to match app directory structure)
28 - '(home)/docs/[[...slug]]': source.getPages().map((page) => ({
29 - value: { slug: page.slugs },
30 - hashes: getHeadings(page),
31 - })),
32 - '(home)/reference/[[...slug]]': referenceSource.getPages().map((page) => ({
33 - value: { slug: page.slugs },
34 - hashes: getHeadings(page),
35 - })),
36 - '(home)/cookbooks/[[...slug]]': cookbooksSource.getPages().map((page) => ({
37 - value: { slug: page.slugs },
38 - hashes: getHeadings(page),
39 - })),
40 - '(home)/toolkits/[[...slug]]': toolkitsSource.getPages().map((page) => ({
41 - value: { slug: page.slugs },
42 - hashes: getHeadings(page),
43 - })),
100 + // Keys must include (home) route group to match app directory structure
101 + '(home)/docs/[[...slug]]': docsEntries,
102 + '(home)/reference/[[...slug]]': refEntries,
103 + '(home)/cookbooks/[[...slug]]': cookbookEntries,
104 + '(home)/toolkits/[[...slug]]': toolkitEntries,
105 },
106 });
107
@@ -70,11 +131,6 @@ async function checkLinks() {
131 }
132 }
133
73 -function getHeadings({ data }: InferPageType<AnySource>): string[] {
74 - if (!data.toc) return [];
75 - return data.toc.map((item) => item.url.slice(1));
76 -}
77 -
134 async function getFiles(): Promise<FileObject[]> {
135 const sources = [source, referenceSource, cookbooksSource, toolkitsSource];
136 const allFiles: FileObject[] = [];