From 6d7a0ed93b660e41e44ffb6a5e153c5197b33d56 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 2 Feb 2026 10:45:42 -0500 Subject: [PATCH] fix(docs): replace in copy-page and markdown output The tag on /docs/components was emitted as-is by the Copy Page button and the /llm/[slug] markdown endpoint because getComponentsList() walked components.children for pages directly. After #9304 restructured the folder into components/radix/ and components/base/ subfolders, the filter always returned [] and the tag was replaced with an empty string (or, in the copy-page case, never replaced at all). - Reuse getPagesFromFolder() from lib/page-tree so the walker stays in sync with the on-screen ComponentsList React component. - Match the existing llms.txt format: flat absolute URLs (the /docs/components/:name -> /docs/components/radix/:name redirect in next.config.mjs is the canonical form) plus the frontmatter description pulled via source.getPage() on each page. - Export replaceComponentsList() and call it from docs/[[...slug]]/page.tsx so the Copy Page button goes through the same replacement path as processMdxForLLMs. --- apps/v4/app/(app)/docs/[[...slug]]/page.tsx | 3 +- apps/v4/lib/llm.ts | 36 +++++++++++---------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/apps/v4/app/(app)/docs/[[...slug]]/page.tsx b/apps/v4/app/(app)/docs/[[...slug]]/page.tsx index 85bcfe394f..c01edaac4d 100644 --- a/apps/v4/app/(app)/docs/[[...slug]]/page.tsx +++ b/apps/v4/app/(app)/docs/[[...slug]]/page.tsx @@ -4,6 +4,7 @@ import { mdxComponents } from "@/mdx-components" import { IconArrowLeft, IconArrowRight } from "@tabler/icons-react" import { findNeighbour } from "fumadocs-core/page-tree" +import { replaceComponentsList } from "@/lib/llm" import { source } from "@/lib/source" import { absoluteUrl } from "@/lib/utils" import { DocsBaseSwitcher } from "@/components/docs-base-switcher" @@ -83,7 +84,7 @@ export default async function Page(props: { const neighbours = isChangelog ? { previous: null, next: null } : findNeighbour(source.pageTree, page.url) - const raw = await page.data.getText("raw") + const raw = replaceComponentsList(await page.data.getText("raw")) return (
page.$id === "components" ) - - if (components?.type !== "folder") { - return "" - } - - const list = components.children.filter( - (component) => component.type === "page" - ) - - return list - .map((component) => `- [${component.name}](${component.url})`) - .join("\n") + const list = + componentsFolder?.type === "folder" + ? getPagesFromFolder(componentsFolder as PageTreeFolder, "radix") + .map((component) => { + const slug = component.url.replace(/^\/docs\//, "").split("/") + const description = source.getPage(slug)?.data.description?.trim() + const url = absoluteUrl(component.url.replace("/radix/", "/")) + return `- [${component.name}](${url})${ + description ? `: ${description}` : "" + }` + }) + .join("\n") + : "" + return content.replace(//g, list) } export function processMdxForLLMs(content: string, style: Style["name"]) { - // Replace with a markdown list of components. - const componentsListRegex = //g - content = content.replace(componentsListRegex, getComponentsList()) + content = replaceComponentsList(content) const componentPreviewRegex = //g