Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
feat: serve docs as agent-readable markdown
kapishdimaf3f12eb6c087
diff --git a/app/llms-components.txt/route.ts b/app/llms-components.txt/route.tsnew file mode 100644index 00000000..d2a4c56b--- /dev/null+++ b/app/llms-components.txt/route.ts@@ -0,0 +1,107 @@+import { formatLength, SITE_URL } from "@/lib/get-llm-text";+import remocnRegistry from "@/registry/remocn/registry.json";+import iconsRegistry from "@/registry/remocn-icons/registry.json";+import remocnUiRegistry from "@/registry/remocn-ui/registry.json";+import { source } from "@/source";++export const revalidate = false;++const TIERS = [+ { tier: "remocn", items: remocnRegistry.items },+ { tier: "remocn-ui", items: remocnUiRegistry.items },+ { tier: "remocn-icons", items: iconsRegistry.items },+] as const;++type RegistryFacts = { tier: string; deps: string[] };++const REGISTRY = new Map<string, RegistryFacts>();+for (const { tier, items } of TIERS) {+ for (const item of items as {+ name: string;+ registryDependencies?: string[];+ }[]) {+ REGISTRY.set(item.name, { tier, deps: item.registryDependencies ?? [] });+ }+}++function sectionTitle(slug: string): string {+ return slug+ ? slug.replace(+ /(^|-)([a-z])/g,+ (_, sep, c) => (sep ? " " : "") + c.toUpperCase(),+ )+ : "Overview";+}++function cell(value: string | undefined): string {+ if (!value) return "—";+ return value+ .replace(/\|/g, "\\|")+ .replace(/\s*\n\s*/g, " ")+ .trim();+}++export function GET() {+ const lines: string[] = [+ "# remocn Component Index",+ "",+ "> Router for every installable remocn component. Scan the tables, pick candidates by",+ "> `Use for` / `Avoid for`, then fetch only the component pages you need.",+ "",+ `Full reference for one component — props, examples, all use / don't-use notes — lives at its`,+ "Docs link below. Every docs URL also serves raw Markdown: append `.md`.",+ "",+ "Install any entry: `npx shadcn@latest add @remocn/<name>` (lands in `components/remocn/`;",+ "`registryDependencies` install transitively).",+ "",+ "`Length` is the component's natural duration at 30fps — budget its `Sequence` accordingly.",+ "`Vibe` is the tonal tag; match it to the brand rather than mixing freely.",+ ];++ const sections = new Map<string, ReturnType<typeof source.getPages>>();+ for (const page of source.getPages()) {+ if (!page.data.component) continue;+ const key = page.slugs[0] ?? "";+ const bucket = sections.get(key) ?? [];+ bucket.push(page);+ sections.set(key, bucket);+ }++ for (const [key, pages] of sections) {+ lines.push("", `## ${sectionTitle(key)}`, "");+ lines.push(+ "| Component | Use for | Avoid for | Length | Vibe | Tier | Deps | Docs |",+ );+ lines.push("|---|---|---|---|---|---|---|---|");++ for (const page of pages.sort((a, b) =>+ a.slugs.join("/").localeCompare(b.slugs.join("/")),+ )) {+ const data = page.data;+ const name = data.component as string;+ const facts = REGISTRY.get(name);+ const deps = facts?.deps.length+ ? facts.deps.map((d) => `\`${d}\``).join(", ")+ : "—";++ lines.push(+ [+ "",+ `\`${name}\``,+ cell(data.useWhen?.[0]),+ cell(data.avoidWhen?.[0]),+ data.length ? formatLength(data.length).replace(" @ 30fps", "") : "—",+ data.vibe ?? "—",+ facts?.tier ?? "—",+ deps,+ `[docs](${SITE_URL}${page.url}.md)`,+ "",+ ].join(" | "),+ );+ }+ }++ return new Response(`${lines.join("\n")}\n`, {+ headers: { "Content-Type": "text/plain; charset=utf-8" },+ });+}diff --git a/app/llms.txt/route.ts b/app/llms.txt/route.tsindex 6770ced9..f1a00d87 100644--- a/app/llms.txt/route.ts+++ b/app/llms.txt/route.ts@@ -16,6 +16,11 @@ export function GET() {"\nDocs are also available as raw Markdown: append `.md` to any docs URL, or read [/llms-full.txt](" +`${SITE_URL}/llms-full.txt) for the full corpus in a single file.`,);+ scanned.push(+ `\nBuilding a video? Start at [/llms-components.txt](${SITE_URL}/llms-components.txt) — every` ++ " installable component in one table with its use / avoid signal, natural length, vibe and" ++ " dependencies, linking to each component's full page.",+ );// Group pages by their top-level section (first slug segment).const sections = new Map<string, ReturnType<typeof source.getPages>>();diff --git a/bun.lock b/bun.lockindex 2c256067..ec736668 100644--- a/bun.lock+++ b/bun.lock@@ -27,6 +27,7 @@"fumadocs-mdx": "^14.2.11","fumadocs-ui": "^16.7.10","jotai": "^2.19.1",+ "json5": "^2.2.3","lucide-react": "^1.7.0","motion": "^12.40.0","next": "16.2.10",diff --git a/lib/docs-schema.ts b/lib/docs-schema.tsnew file mode 100644index 00000000..3f211df3--- /dev/null+++ b/lib/docs-schema.ts@@ -0,0 +1,21 @@+import { z } from "zod";++export const VIBES = [+ "clean",+ "premium",+ "tech",+ "data",+ "playful",+ "social",+ "paper",+] as const;++export type Vibe = (typeof VIBES)[number];++export const componentMetaSchema = z.object({+ component: z.string().optional(),+ vibe: z.enum(VIBES).optional(),+ length: z.union([z.int().positive(), z.literal("state-driven")]).optional(),+ useWhen: z.array(z.string()).optional(),+ avoidWhen: z.array(z.string()).optional(),+});diff --git a/lib/get-llm-text.ts b/lib/get-llm-text.tsindex 682d8b44..a3e9ad9b 100644--- a/lib/get-llm-text.ts+++ b/lib/get-llm-text.ts@@ -1,28 +1,48 @@import type { InferPageType } from "fumadocs-core/source";+import { mdxToMarkdown, stripFrontmatter } from "@/lib/mdx-to-markdown";import type { source } from "@/source";export const SITE_URL = "https://remocn.dev";type DocPage = InferPageType<typeof source>;-/**- * Render a single doc page as a self-contained Markdown document for LLMs.- * Uses the processed Markdown emitted by fumadocs-mdx (`includeProcessedMarkdown`- * in source.config.ts), prefixed with a title + source URL header.- */+export function formatLength(length: number | "state-driven"): string {+ return length === "state-driven" ? "state-driven" : `${length}f @ 30fps`;+}+export async function getLLMText(page: DocPage): Promise<string> {const data = page.data as typeof page.data & {getText: (type: "raw" | "processed") => Promise<string>;};- const processed = await data.getText("processed");-- return [- `# ${data.title}`,- `URL: ${SITE_URL}${page.url}`,- data.description ? `\n${data.description}` : "",- "",- processed,- ]- .filter(Boolean)- .join("\n");++ const raw = await data.getText("raw");+ const body = mdxToMarkdown(stripFrontmatter(raw), SITE_URL).trim();++ const facts: string[] = [];+ if (data.component)+ facts.push(+ `- Install: \`npx shadcn@latest add @remocn/${data.component}\``,+ );+ if (data.vibe) facts.push(`- Vibe: ${data.vibe}`);+ if (data.length) facts.push(`- Natural length: ${formatLength(data.length)}`);++ const blocks = [+ `# ${data.title}\nURL: ${SITE_URL}${page.url}`,+ data.description,+ facts.join("\n"),+ body,+ ];++ if (data.useWhen?.length) {+ blocks.push(+ `## Use when\n${data.useWhen.map((line) => `- ${line}`).join("\n")}`,+ );+ }+ if (data.avoidWhen?.length) {+ blocks.push(+ `## Don't use when\n${data.avoidWhen.map((line) => `- ${line}`).join("\n")}`,+ );+ }++ return blocks.filter(Boolean).join("\n\n");}diff --git a/lib/mdx-to-markdown.ts b/lib/mdx-to-markdown.tsnew file mode 100644index 00000000..8616a87a--- /dev/null+++ b/lib/mdx-to-markdown.ts@@ -0,0 +1,329 @@+import JSON5 from "json5";+import { INSTALL_ALL_COMMAND } from "@/config/site";++type AttrValue =+ | string+ | number+ | boolean+ | null+ | AttrValue[]+ | { [k: string]: AttrValue };++interface PropRow {+ name?: string;+ type?: string;+ default?: string;+ required?: boolean;+ description?: string;+}++interface CardItem {+ name?: string;+ description?: string;+ status?: string;+ href?: string;+}++const DROPPED_WIDGETS = new Set([+ "ComponentPreview",+ "UiComponentPreview",+ "BlockPreview",+ "ComponentExample",+ "IconsGallery",+ "GuideVideo",+]);++const CONTAINER_WIDGETS = new Set(["Note", "Warning"]);++const SELF_CLOSING_WIDGETS = new Set([+ ...DROPPED_WIDGETS,+ "InstallBlock",+ "InstallAll",+ "PropsTable",+ "Dependencies",+ "ComponentCardGrid",+]);++function skipQuoted(src: string, start: number): number {+ const quote = src[start];+ let i = start + 1;+ while (i < src.length) {+ if (src[i] === "\\") {+ i += 2;+ continue;+ }+ if (src[i] === quote) return i + 1;+ i += 1;+ }+ return i;+}++function findTagEnd(+ src: string,+ start: number,+): { end: number; selfClosing: boolean } | null {+ let i = start;+ let depth = 0;+ while (i < src.length) {+ const c = src[i];+ if (c === '"' || c === "'" || c === "`") {+ i = skipQuoted(src, i);+ continue;+ }+ if (c === "{") {+ depth += 1;+ i += 1;+ continue;+ }+ if (c === "}") {+ depth -= 1;+ i += 1;+ continue;+ }+ if (depth === 0) {+ if (c === "/" && src[i + 1] === ">")+ return { end: i + 2, selfClosing: true };+ if (c === ">") return { end: i + 1, selfClosing: false };+ }+ i += 1;+ }+ return null;+}++function parseAttrs(raw: string): Record<string, AttrValue> {+ const attrs: Record<string, AttrValue> = {};+ let i = 0;+ while (i < raw.length) {+ while (i < raw.length && /\s/.test(raw[i])) i += 1;+ const nameStart = i;+ while (i < raw.length && /[\w-]/.test(raw[i])) i += 1;+ if (i === nameStart) {+ i += 1;+ continue;+ }+ const name = raw.slice(nameStart, i);+ while (i < raw.length && /\s/.test(raw[i])) i += 1;+ if (raw[i] !== "=") {+ attrs[name] = true;+ continue;+ }+ i += 1;+ while (i < raw.length && /\s/.test(raw[i])) i += 1;+ if (raw[i] === '"' || raw[i] === "'") {+ const end = skipQuoted(raw, i);+ attrs[name] = raw.slice(i + 1, end - 1);+ i = end;+ continue;+ }+ if (raw[i] === "{") {+ let depth = 0;+ const exprStart = i;+ while (i < raw.length) {+ const c = raw[i];+ if (c === '"' || c === "'" || c === "`") {+ i = skipQuoted(raw, i);+ continue;+ }+ if (c === "{") depth += 1;+ if (c === "}") {+ depth -= 1;+ if (depth === 0) {+ i += 1;+ break;+ }+ }+ i += 1;+ }+ const expr = raw.slice(exprStart + 1, i - 1);+ try {+ attrs[name] = JSON5.parse(expr);+ } catch {+ attrs[name] = expr.trim();+ }+ continue;+ }+ i += 1;+ }+ return attrs;+}++function cell(value: string | undefined): string {+ if (!value) return "—";+ return value+ .replace(/\|/g, "\\|")+ .replace(/\s*\n\s*/g, " ")+ .trim();+}++function renderPropsTable(rows: unknown): string {+ if (!Array.isArray(rows)) return "";+ const lines = [+ "| Prop | Type | Default | Description |",+ "|---|---|---|---|",+ ];+ for (const row of rows as PropRow[]) {+ const name = row.required+ ? `\`${row.name}\` (required)`+ : `\`${row.name}\``;+ const type = row.type ? `\`${cell(row.type)}\`` : "—";+ const fallback = row.default ? `\`${cell(row.default)}\`` : "—";+ lines.push(+ `| ${name} | ${type} | ${fallback} | ${cell(row.description)} |`,+ );+ }+ return lines.join("\n");+}++function renderCardGrid(items: unknown, siteUrl: string): string {+ if (!Array.isArray(items)) return "";+ return (items as CardItem[])+ .map((item) => {+ const label = item.href+ ? `[${item.name}](${item.href.startsWith("/") ? siteUrl + item.href : item.href})`+ : item.name;+ const soon = item.status === "soon" ? " _(coming soon)_" : "";+ return `- ${label}${soon} — ${item.description ?? ""}`.trimEnd();+ })+ .join("\n");+}++function renderDependencies(items: unknown): string {+ if (!Array.isArray(items) || items.length === 0) return "";+ return `Requires: ${items.map((i) => `\`${String(i)}\``).join(", ")}`;+}++function blockquote(body: string, label: string): string {+ const trimmed = body.trim();+ if (!trimmed) return "";+ const lines = [`**${label}**`, "", trimmed].join("\n");+ return lines+ .split("\n")+ .map((line) => (line ? `> ${line}` : ">"))+ .join("\n");+}++function findClosingTag(src: string, tag: string, from: number): number {+ const open = new RegExp(`<${tag}[\\s>]`, "g");+ const close = new RegExp(`</${tag}\\s*>`, "g");+ let depth = 1;+ let cursor = from;+ while (cursor < src.length) {+ close.lastIndex = cursor;+ const nextClose = close.exec(src);+ if (!nextClose) return -1;+ open.lastIndex = cursor;+ let nested = 0;+ let m = open.exec(src);+ while (m && m.index < nextClose.index) {+ nested += 1;+ m = open.exec(src);+ }+ depth += nested - 1;+ if (depth === 0) return nextClose.index;+ cursor = nextClose.index + nextClose[0].length;+ }+ return -1;+}++export function stripFrontmatter(src: string): string {+ if (!src.startsWith("---")) return src;+ const end = src.indexOf("\n---", 3);+ if (end === -1) return src;+ const after = src.indexOf("\n", end + 1);+ return after === -1 ? "" : src.slice(after + 1);+}++export function mdxToMarkdown(src: string, siteUrl: string): string {+ let out = "";+ let i = 0;++ while (i < src.length) {+ const atLineStart = i === 0 || src[i - 1] === "\n";++ if (atLineStart) {+ const fence = /^([ \t]{0,3})(`{3,}|~{3,})/.exec(src.slice(i));+ if (fence) {+ const marker = fence[2];+ const closeRe = new RegExp(+ `\\n[ \\t]{0,3}\\${marker[0]}{${marker.length},}[ \\t]*(?=\\n|$)`,+ );+ const rest = src.slice(i);+ const lineEnd = rest.indexOf("\n");+ const search = lineEnd === -1 ? "" : rest.slice(lineEnd);+ const closing = closeRe.exec(search);+ const blockEnd =+ closing && lineEnd !== -1+ ? i + lineEnd + closing.index + closing[0].length+ : src.length;+ out += src.slice(i, blockEnd);+ i = blockEnd;+ continue;+ }+ }++ if (src[i] === "<") {+ const nameMatch = /^<([A-Z][A-Za-z0-9]*)/.exec(src.slice(i));+ const tag = nameMatch?.[1];+ if (+ tag &&+ (SELF_CLOSING_WIDGETS.has(tag) || CONTAINER_WIDGETS.has(tag))+ ) {+ const tagEnd = findTagEnd(src, i + 1 + tag.length);+ if (tagEnd) {+ const attrs = parseAttrs(+ src.slice(+ i + 1 + tag.length,+ tagEnd.end - (tagEnd.selfClosing ? 2 : 1),+ ),+ );++ if (CONTAINER_WIDGETS.has(tag) && !tagEnd.selfClosing) {+ const closeIndex = findClosingTag(src, tag, tagEnd.end);+ if (closeIndex !== -1) {+ const inner = mdxToMarkdown(+ src.slice(tagEnd.end, closeIndex),+ siteUrl,+ );+ const label = typeof attrs.title === "string" ? attrs.title : tag;+ out += blockquote(inner, label);+ i = closeIndex + `</${tag}>`.length;+ continue;+ }+ }++ if (DROPPED_WIDGETS.has(tag)) {+ i = tagEnd.end;+ while (src[i] === "\n" && src[i + 1] === "\n") i += 1;+ continue;+ }++ let replacement = "";+ if (tag === "InstallBlock" && typeof attrs.name === "string") {+ replacement = [+ "```bash",+ `npx shadcn@latest add @remocn/${attrs.name}`,+ "```",+ ].join("\n");+ } else if (tag === "InstallAll") {+ replacement = ["```bash", INSTALL_ALL_COMMAND, "```"].join("\n");+ } else if (tag === "PropsTable") {+ replacement = renderPropsTable(attrs.rows);+ } else if (tag === "ComponentCardGrid") {+ replacement = renderCardGrid(attrs.items, siteUrl);+ } else if (tag === "Dependencies") {+ replacement = renderDependencies(attrs.items);+ }++ out += replacement;+ i = tagEnd.end;+ continue;+ }+ }+ }++ out += src[i];+ i += 1;+ }++ return out;+}diff --git a/package.json b/package.jsonindex 278eb57f..e39d00ad 100644--- a/package.json+++ b/package.json@@ -42,6 +42,7 @@"fumadocs-mdx": "^14.2.11","fumadocs-ui": "^16.7.10","jotai": "^2.19.1",+ "json5": "^2.2.3","lucide-react": "^1.7.0","motion": "^12.40.0","next": "16.2.10",diff --git a/source.config.ts b/source.config.tsindex 9417b159..d2658541 100644--- a/source.config.ts+++ b/source.config.ts@@ -7,11 +7,12 @@ import {import rehypePrettyCode from "rehype-pretty-code";import type { ShikiTransformer } from "shiki";import { z } from "zod";+import { componentMetaSchema } from "./lib/docs-schema";export const docs = defineDocs({dir: "content/docs",docs: {- schema: pageSchema,+ schema: pageSchema.extend(componentMetaSchema.shape),postprocess: {includeProcessedMarkdown: true,},