Files
shadcn-ui/apps/v4/lib/llm.ts
shadcn 02d5ce85ec feat: upgrade to Next.js 16 (#8615)
* feat: upgrade to Next.js 16

* chore: deps

* fix

* fix

* fix

* fix: workaround zod 4 for now

* fix

* fix: copy button

* fix: update apps/v4/hooks/use-is-mac.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix

* fix: remove

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-29 13:37:41 +04:00

34 lines
832 B
TypeScript

import fs from "fs"
import { Index } from "@/registry/__index__"
export function processMdxForLLMs(content: string) {
const componentPreviewRegex =
/<ComponentPreview[\s\S]*?name="([^"]+)"[\s\S]*?\/>/g
return content.replace(componentPreviewRegex, (match, name) => {
try {
const component = Index[name]
if (!component?.files) {
return match
}
const src = component.files[0]?.path
if (!src) {
return match
}
let source = fs.readFileSync(src, "utf8")
source = source.replaceAll(`@/registry/new-york-v4/`, "@/components/")
source = source.replaceAll("export default", "export")
return `\`\`\`tsx
${source}
\`\`\``
} catch (error) {
console.error(`Error processing ComponentPreview ${name}:`, error)
return match
}
})
}