mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-27 14:44:12 +00:00
* feat: refactor registry * fix: remove components * refactor: getActiveStyle * fix: prettier in build-registry Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix * Update apps/v4/scripts/build-registry.mts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix * Update apps/v4/scripts/build-registry.mts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update apps/v4/components/block-viewer.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
35 lines
910 B
TypeScript
35 lines
910 B
TypeScript
import fs from "fs"
|
|
|
|
import { Index } from "@/registry/__index__"
|
|
import { type Style } from "@/registry/styles"
|
|
|
|
export function processMdxForLLMs(content: string, style: Style["name"]) {
|
|
const componentPreviewRegex =
|
|
/<ComponentPreview[\s\S]*?name="([^"]+)"[\s\S]*?\/>/g
|
|
|
|
return content.replace(componentPreviewRegex, (match, name) => {
|
|
try {
|
|
const component = Index[style]?.[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
|
|
}
|
|
})
|
|
}
|