From 6a60977eb5a004145036c4fef8eae0698852fa95 Mon Sep 17 00:00:00 2001 From: Luca Martial <48870843+luca-martial@users.noreply.github.com> Date: Mon, 18 May 2026 09:59:01 -0400 Subject: [PATCH] fix(docs): replace broken page copy buttons with working single button (#132) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The three page-level buttons (Copy MD, View MD, Copy MDX) were broken because the fetch URL missed the /ktx basePath. Replace with a single "Copy as Markdown" button that strips frontmatter from the MDX source already available client-side — no fetch needed. Drop the .md link since agents discover markdown URLs through llms.txt and content negotiation. Co-authored-by: Claude Opus 4.6 (1M context) --- docs-site/app/docs/[[...slug]]/page.tsx | 5 +- docs-site/components/docs-page-actions.tsx | 120 +++++---------------- 2 files changed, 25 insertions(+), 100 deletions(-) diff --git a/docs-site/app/docs/[[...slug]]/page.tsx b/docs-site/app/docs/[[...slug]]/page.tsx index dd5d944c..e0677c9e 100644 --- a/docs-site/app/docs/[[...slug]]/page.tsx +++ b/docs-site/app/docs/[[...slug]]/page.tsx @@ -51,10 +51,7 @@ export default async function Page(props: { <>
{page.data.title} - +
{page.data.description} diff --git a/docs-site/components/docs-page-actions.tsx b/docs-site/components/docs-page-actions.tsx index 95bf93a4..96d3980b 100644 --- a/docs-site/components/docs-page-actions.tsx +++ b/docs-site/components/docs-page-actions.tsx @@ -2,109 +2,37 @@ import { useState } from "react"; -type CopyState = "idle" | "copied" | "error"; - type Props = { - markdownUrl: string; mdxSource: string; }; -export function DocsPageActions({ markdownUrl, mdxSource }: Props) { +function stripFrontmatter(source: string) { + return source.trim().replace(/^---\n[\s\S]*?\n---\n?/, "").trim(); +} + +export function DocsPageActions({ mdxSource }: Props) { + const [copied, setCopied] = useState(false); + + const onCopy = async () => { + try { + await navigator.clipboard.writeText(stripFrontmatter(mdxSource)); + setCopied(true); + setTimeout(() => setCopied(false), 1500); + } catch { + // Clipboard denied — fail silently + } + }; + return (
- - - View MD - - + {copied ? "Copied" : "Copy as Markdown"} +
); } - -function CopyMarkdownButton({ markdownUrl }: { markdownUrl: string }) { - const [state, setState] = useState("idle"); - - const onClick = async () => { - try { - const response = await fetch(markdownUrl, { - headers: { Accept: "text/markdown" }, - }); - - if (!response.ok) { - throw new Error(`Failed to fetch ${markdownUrl}`); - } - - await navigator.clipboard.writeText(await response.text()); - flash(setState, "copied"); - } catch { - flash(setState, "error"); - } - }; - - return ( - - ); -} - -function CopyTextButton({ label, text }: { label: string; text: string }) { - const [state, setState] = useState("idle"); - - const onClick = async () => { - try { - await navigator.clipboard.writeText(text); - flash(setState, "copied"); - } catch { - flash(setState, "error"); - } - }; - - return ( - - ); -} - -function ActionButton({ - label, - onClick, - state, -}: { - label: string; - onClick: () => void; - state: CopyState; -}) { - return ( - - ); -} - -function labelForState(state: CopyState, label: string) { - if (state === "copied") return "Copied"; - if (state === "error") return "Copy failed"; - return label; -} - -function flash( - setState: (state: CopyState) => void, - state: Exclude, -) { - setState(state); - window.setTimeout(() => setState("idle"), 1500); -}