diff --git a/docs/site/app/(sidebar)/docs/[[...slug]]/layout.tsx b/docs/site/app/(sidebar)/docs/[[...slug]]/layout.tsx index a72d3566aae61..98f194646375e 100644 --- a/docs/site/app/(sidebar)/docs/[[...slug]]/layout.tsx +++ b/docs/site/app/(sidebar)/docs/[[...slug]]/layout.tsx @@ -17,7 +17,7 @@ export default async function SlugLayout(props: { } return ( - + {children} ); diff --git a/docs/site/app/(sidebar)/docs/[[...slug]]/page.tsx b/docs/site/app/(sidebar)/docs/[[...slug]]/page.tsx index 4f803e9f5515b..e69d0c7dde594 100644 --- a/docs/site/app/(sidebar)/docs/[[...slug]]/page.tsx +++ b/docs/site/app/(sidebar)/docs/[[...slug]]/page.tsx @@ -1,9 +1,11 @@ import { notFound } from "next/navigation"; +import { readFileSync } from "fs"; import type { Metadata } from "next/types"; import { repoDocsPages } from "@/app/source"; import { createMetadata } from "@/lib/create-metadata"; import { mdxComponents } from "@/mdx-components"; import { SystemEnvironmentVariablesHashHighlighter } from "./system-environment-variables-hash-highlighter"; +import { CopyToMarkdown } from "@/components/copy-to-markdown"; export async function generateMetadata(props: { params: Promise<{ slug?: string[] }>; @@ -36,14 +38,25 @@ export default async function Page(props: { notFound(); } + const rawMarkdown = readFileSync(page.data._file.absolutePath) + .toString() + // Removes frontmatter + .replace(/^---\n(.*?\n)---\n/s, "") + // Removes import statements for components + .replace(/^import\s+{[^}]+}\s+from\s+['"]#\/[^'"]+['"];(\r?\n|$)/gm, ""); + const Mdx = page.data.body; return ( <> -

- {page.data.title} -

+
+

+ {page.data.title} +

+ + +
); diff --git a/docs/site/components/copy-to-markdown.tsx b/docs/site/components/copy-to-markdown.tsx new file mode 100644 index 0000000000000..74abff8abe7bf --- /dev/null +++ b/docs/site/components/copy-to-markdown.tsx @@ -0,0 +1,40 @@ +"use client"; + +import { useState } from "react"; +import { Copy, Check } from "lucide-react"; +import { Button } from "./button"; +import { cn } from "./cn"; + +export const CopyToMarkdown = ({ + markdownContent, +}: { + markdownContent: string; +}) => { + const [copied, setCopied] = useState(false); + + const handleCopy = async () => { + await navigator.clipboard.writeText(markdownContent); + setCopied(true); + + // Reset back to copy icon after 2 seconds + setTimeout(() => { + setCopied(false); + }, 2000); + }; + + return ( + + ); +}; diff --git a/docs/site/tsconfig.json b/docs/site/tsconfig.json index 0619401c65321..367e429ecb6e4 100644 --- a/docs/site/tsconfig.json +++ b/docs/site/tsconfig.json @@ -15,7 +15,7 @@ "#/*": ["./*"] }, "allowJs": true, - "target": "ES2017", + "target": "ESNext", "lib": ["dom", "dom.iterable", "esnext"], "noEmit": true, "incremental": true