Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
feat(docs): add Copy Page button for AI-friendly content
Add button that copies the page's markdown content to clipboard. Fetches from the .md endpoint for clean, AI-ready content. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sushmithamallesh committed
Jan 19, 2026 at 14:15 UTC
358739fe39759a87c804c497113c30a858d6805c
2 files changed
+57
-1
docs/app/(home)/docs/[[...slug]]/page.tsx
+5
-1
@@ -9,6 +9,7 @@ import { notFound } from 'next/navigation';
9
import { getMDXComponents } from '@/mdx-components';
10
import type { Metadata } from 'next';
11
import { createRelativeLink } from 'fumadocs-ui/mdx';
12
+import { CopyPage } from '@/components/copy-page';
13
14
export default async function Page(props: PageProps<'/docs/[[...slug]]'>) {
15
const params = await props.params;
@@ -22,7 +23,10 @@ export default async function Page(props: PageProps<'/docs/[[...slug]]'>) {
23
return (
24
<DocsPage toc={data.toc} full={data.full} footer={{ enabled: false }} tableOfContentPopover={{ enabled: false }}>
25
<DocsTitle>{data.title}</DocsTitle>
25
- <DocsDescription className="mb-4">{data.description}</DocsDescription>
26
+ <DocsDescription>{data.description}</DocsDescription>
27
+ <div className="flex items-center gap-2 mt-2 mb-6">
28
+ <CopyPage path={page.url} />
29
+ </div>
30
<DocsBody>
31
<MDX
32
components={getMDXComponents({
docs/components/copy-page.tsx
new
+52
@@ -0,0 +1,52 @@
1
+'use client';
2
+
3
+import { useState } from 'react';
4
+import { Copy, Check, Loader2 } from 'lucide-react';
5
+
6
+interface CopyPageProps {
7
+ /** The URL path to fetch markdown from (e.g., /docs/quickstart) */
8
+ path: string;
9
+}
10
+
11
+/**
12
+ * Button that copies the current page's markdown content to clipboard.
13
+ * Fetches from the .md endpoint for clean, AI-friendly content.
14
+ */
15
+export function CopyPage({ path }: CopyPageProps) {
16
+ const [state, setState] = useState<'idle' | 'loading' | 'copied'>('idle');
17
+
18
+ const handleCopy = async () => {
19
+ setState('loading');
20
+
21
+ try {
22
+ const response = await fetch(`${path}.md`);
23
+ if (!response.ok) throw new Error('Failed to fetch');
24
+
25
+ const markdown = await response.text();
26
+ await navigator.clipboard.writeText(markdown);
27
+
28
+ setState('copied');
29
+ setTimeout(() => setState('idle'), 2000);
30
+ } catch {
31
+ setState('idle');
32
+ }
33
+ };
34
+
35
+ return (
36
+ <button
37
+ onClick={handleCopy}
38
+ disabled={state === 'loading'}
39
+ className="inline-flex items-center gap-1.5 px-3 py-1.5 text-sm font-medium text-fd-muted-foreground hover:text-fd-foreground bg-fd-secondary hover:bg-fd-accent rounded-md transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-orange-500 focus-visible:ring-offset-2 disabled:opacity-50"
40
+ aria-label="Copy page as markdown"
41
+ >
42
+ {state === 'loading' ? (
43
+ <Loader2 className="w-4 h-4 animate-spin" aria-hidden="true" />
44
+ ) : state === 'copied' ? (
45
+ <Check className="w-4 h-4 text-green-500" aria-hidden="true" />
46
+ ) : (
47
+ <Copy className="w-4 h-4" aria-hidden="true" />
48
+ )}
49
+ {state === 'copied' ? 'Copied!' : 'Copy page'}
50
+ </button>
51
+ );
52
+}