mirror of
https://github.com/supabase/supabase.git
synced 2026-09-06 09:59:03 +08:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Feature: agent-readable markdown pages for the UI library docs. ## What is the current behavior? Library docs are HTML-only. `llms.txt` lists page titles, but there is no `.md` body an agent can fetch. ## What is the new behavior? Each docs page is also served as markdown: - Build-time MDX → markdown (`pnpm --filter library build:markdown`) - `GET /library/docs/{slug}.md` (and `Accept: text/markdown`) - HTML pages advertise `rel=alternate` `text/markdown` - `llms.txt` links to the `.md` URLs This is the base of a stack. The prompt-tab PR sits on top: https://github.com/supabase/supabase/pull/49566 ## Additional context Interactive previews are omitted from the markdown. `BlockItem` emits the production `npx shadcn add` command so agents still get an install path. ## To test 1. `pnpm --filter library dev` (generates markdown in `predev`). 2. Open http://localhost:3004/library/docs/nextjs/password-based-auth.md — markdown with the install command, file tree, and setup steps; no interactive previews. 3. Open the same path without `.md` — HTML docs unchanged (no prompt tab in this PR). 4. `curl -H 'Accept: text/markdown' http://localhost:3004/library/docs/nextjs/password-based-auth` should also return markdown. 5. http://localhost:3004/library/llms.txt — links should end in `.md`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Documentation pages are available as Markdown through `.md` URLs and a dedicated endpoint. * Markdown is generated automatically during development and production builds. * Generated content preserves front matter, links, callouts, installation instructions, and supported documentation elements. * Installation commands support npm, pnpm, yarn, and bun for React and Vue projects. * **Bug Fixes** * Improved Markdown file handling, link rewriting, and content negotiation. * **Tests** * Added coverage for Markdown conversion, content negotiation, and installation commands. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Saxon Fletcher <SaxonF@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
export type PackageManager = 'npm' | 'pnpm' | 'yarn' | 'bun'
|
|
export type ShadcnFramework = 'react' | 'vue'
|
|
|
|
export function getShadcnFramework(name: string): ShadcnFramework {
|
|
return name.includes('vue') || name.includes('nuxtjs') ? 'vue' : 'react'
|
|
}
|
|
|
|
export function getRegistryBaseUrl(env = process.env.NEXT_PUBLIC_VERCEL_TARGET_ENV): string {
|
|
if (env === 'production') {
|
|
// Special alias for production, added in https://github.com/shadcn-ui/ui/pull/8161
|
|
return '@supabase'
|
|
}
|
|
if (env === 'preview') {
|
|
return `https://${process.env.NEXT_PUBLIC_VERCEL_BRANCH_URL}`
|
|
}
|
|
return 'http://localhost:3004'
|
|
}
|
|
|
|
export function getRegistryComponentPath(
|
|
name: string,
|
|
env = process.env.NEXT_PUBLIC_VERCEL_TARGET_ENV
|
|
): string {
|
|
if (env === 'production') {
|
|
return `/${name}`
|
|
}
|
|
return `${process.env.NEXT_PUBLIC_BASE_PATH ?? ''}/r/${name}.json`
|
|
}
|
|
|
|
export function getInstallCommands(
|
|
name: string,
|
|
options?: { framework?: ShadcnFramework; production?: boolean }
|
|
): Record<PackageManager, string> {
|
|
const framework = options?.framework ?? getShadcnFramework(name)
|
|
const env = options?.production ? 'production' : process.env.NEXT_PUBLIC_VERCEL_TARGET_ENV
|
|
const specifier = `${getRegistryBaseUrl(env)}${getRegistryComponentPath(name, env)}`
|
|
const cli = framework === 'vue' ? 'shadcn-vue@latest' : 'shadcn@latest'
|
|
|
|
return {
|
|
npm: `npx ${cli} add ${specifier}`,
|
|
pnpm: `pnpm dlx ${cli} add ${specifier}`,
|
|
yarn: `yarn dlx ${cli} add ${specifier}`,
|
|
bun: `bunx --bun ${cli} add ${specifier}`,
|
|
}
|
|
}
|