agentleFS
strongeronstrongeron/ui-guides-agent-rules/.claude/skills/mdx-content-stack/SKILL.md

mdx-content-stack

Skill1 starsChanged 10 months agoMITView on GitHub

Build content-driven React apps with MDX, Vite, and auto-discovered components. Use when creating documentation sites, guidelines showcases, educational platforms, pattern libraries, or any project needing rich content pages with interactive React components embedded in markdown.

  • Installs packages

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 8 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Pure SPA: - No content pages, just app UI

    line 94
  2. Distinctive:

    Content from external CMS: - Use CMS API instead

    line 97
  3. Very specific:

    High SEO needs: - Consider Next.js/Astro with SSG

    line 98
  4. Distinctive:

    Create reusable components for consistent content patterns:

    line 137
  5. Distinctive:

    Keep MDX files focused on content - complex logic belongs in components

    line 330
  6. Distinctive:

    Use frontmatter for metadata, not configuration

    line 331
  7. Distinctive:

    Create custom MDX components for repeated content patterns

    line 333
  8. Distinctive:

    Don't: Import components in every MDX file

    line 340
  9. Distinctive:

    Do:: Create domain-specific MDX components

    line 346

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

MDX Content Stack

Build content-driven React applications where MDX files define pages with embedded interactive components, frontmatter metadata, and auto-discovery patterns.

Quick Start

1. Vite MDX Setup:

// vite.config.ts
import mdx from '@mdx-js/rollup';
import remarkGfm from 'remark-gfm';
import remarkFrontmatter from 'remark-frontmatter';
import remarkMdxFrontmatter from 'remark-mdx-frontmatter';
import rehypeSlug from 'rehype-slug';

export default defineConfig({
  plugins: [
    mdx({
      remarkPlugins: [
        remarkGfm,
        remarkFrontmatter,
        [remarkMdxFrontmatter, { name: 'frontmatter' }],
      ],
      rehypePlugins: [rehypeSlug],
      providerImportSource: '@mdx-js/react',
    }),
    react({ include: /\.(jsx|js|mdx|md|tsx|ts)$/ }),
  ],
});

2. Create MDX Content:

---
id: my-principle
category: forms
title: Enter Submits
description: When a text input is focused, Enter should submit
badExampleKey: forms-enter-submits-bad
goodExampleKey: forms-enter-submits-good
---

import { Callout, ExampleComparison } from '@/components/mdx';

<Callout type="quote" title="From the Guidelines">
  Enter submits when a text input is focused.
</Callout>

## Why This Matters

Users expect pressing Enter to submit forms.

<ExampleComparison
  badKey="forms-enter-submits-bad"
  goodKey="forms-enter-submits-good"
/>

3. Auto-Discover Examples:

// ExampleRenderer.tsx
const exampleModules = import.meta.glob<{ [key: string]: ComponentType }>(
  './examples/**/*.tsx',
  { eager: false }
);

// Converts: ./examples/forms/EnterSubmitsBad.tsx → forms-enter-submits-bad

When To Use This Stack

Ideal Use Cases

Project TypeWhy MDX Works
Documentation sitesMix prose with live code examples
Design systemsComponent demos embedded in guidelines
Educational platformsInteractive exercises in lessons
Pattern librariesGood/bad examples with explanations
Style guidesRules with live previews
API referencesEndpoints with playground widgets
TutorialsStep-by-step with runnable code

When NOT To Use

  • Pure SPA - No content pages, just app UI
  • E-commerce - Product pages from CMS/database
  • Real-time apps - Chat, dashboards, collaborative tools
  • Content from external CMS - Use CMS API instead
  • High SEO needs - Consider Next.js/Astro with SSG

Architecture Patterns

Content Organization

content/
└── principles/           # or pages/, docs/, guides/
    ├── animations/
    │   ├── prefers-reduced-motion.mdx
    │   └── compositor-friendly.mdx
    ├── forms/
    │   ├── enter-submits.mdx
    │   └── labels-everywhere.mdx
    └── performance/
        └── minimize-rerenders.mdx

Component Auto-Discovery

Examples are discovered automatically - no manual registration:

src/components/examples/
├── forms/
│   ├── EnterSubmitsGood.tsx    → forms-enter-submits-good
│   └── EnterSubmitsBad.tsx     → forms-enter-submits-bad
└── animations/
    ├── ReducedMotionGood.tsx   → animations-reduced-motion-good
    └── ReducedMotionBad.tsx    → animations-reduced-motion-bad

Key pattern: File path converts to kebab-case key:

  • PascalCase → kebab-case
  • Directory becomes prefix: forms/EnterSubmitsBad.tsx → forms-enter-submits-bad

Custom MDX Components

Create reusable components for consistent content patterns:

// src/components/mdx/index.ts
export { Callout } from './Callout';
export { ExampleComparison } from './ExampleComparison';
export { CodeBlock } from './CodeBlock';

Callout types: info, warning, tip, quote

<Callout type="warning" title="Important">
  This pattern can cause accessibility issues.
</Callout>

Side-by-side comparisons:

<ExampleComparison
  badKey="forms-enter-submits-bad"
  goodKey="forms-enter-submits-good"
  badTitle="Without Enter Submit"
  goodTitle="With Enter Submit"
/>

Frontmatter as Data Source

Frontmatter becomes typed metadata accessible in your app:

// types/principle.ts
interface Principle {
  id: string;
  category: PrincipleCategory;
  title: string;
  description: string;
  badExampleKey: string;
  goodExampleKey: string;
}

type PrincipleCategory = 'forms' | 'animations' | 'layout' | 'content';

Essential Dependencies

{
  "dependencies": {
    // MDX Core
    "@mdx-js/react": "^3.1.1",
    "@mdx-js/rollup": "^3.1.1",
    "remark-frontmatter": "^5.0.0",
    "remark-gfm": "^4.0.1",
    "remark-mdx-frontmatter": "^5.2.0",
    "rehype-slug": "^6.0.0",

    // shadcn/ui + Radix primitives
    "@radix-ui/react-dialog": "^1.1.15",
    "@radix-ui/react-popover": "^1.1.15",
    "@radix-ui/react-switch": "^1.2.6",
    "@radix-ui/react-tabs": "^1.2.6",
    "@radix-ui/react-slot": "^1.2.4",

    // Styling utilities
    "class-variance-authority": "^0.7.1",
    "clsx": "^2.1.1",
    "tailwind-merge": "^3.4.0",

    // Animation (optional)
    "motion": "^12.28.1"
  },
  "devDependencies": {
    "shadcn": "^3.6.0",
    "tailwindcss": "^4.1.18",
    "@tailwindcss/vite": "^4.1.18"
  }
}

shadcn/ui Integration

Setup shadcn with MDX

1. Initialize shadcn:

npx shadcn@latest init

2. components.json configuration:

{
  "$schema": "https://ui.shadcn.com/schema.json",
  "style": "new-york",
  "rsc": false,
  "tsx": true,
  "tailwind": {
    "config": "",
    "css": "src/index.css",
    "baseColor": "stone",
    "cssVariables": true
  },
  "aliases": {
    "components": "@/components",
    "utils": "@/lib/utils",
    "ui": "@/components/ui"
  }
}

3. Add components:

npx shadcn@latest add card button dialog tabs

Using shadcn in MDX Components

Pattern: Wrap shadcn components in domain-specific MDX components:

// src/components/mdx/ExampleComparison.tsx
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { ExampleRenderer } from '../ExampleRenderer';

export function ExampleComparison({ badKey, goodKey }: Props) {
  return (
    <div className="grid grid-cols-1 lg:grid-cols-2 gap-6 my-8">
      <Card className="bg-card shadow-sm">
        <CardHeader>
          <CardTitle className="text-error">Bad Example</CardTitle>
        </CardHeader>
        <CardContent>
          <ExampleRenderer exampleKey={badKey} />
        </CardContent>
      </Card>
      {/* Good example card... */}
    </div>
  );
}

Don't use shadcn directly in MDX files:

// ❌ Avoid - verbose and couples content to UI library
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card';

<Card>
  <CardHeader><CardTitle>Example</CardTitle></CardHeader>
  <CardContent>...</CardContent>
</Card>

Do create semantic MDX wrappers:

// ✅ Clean - semantic, reusable, decoupled
import { ExampleComparison } from '@/components/mdx';

<ExampleComparison badKey="forms-bad" goodKey="forms-good" />

The cn() Utility

Essential for merging Tailwind classes in components:

// src/lib/utils.ts
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs))
}

Usage in MDX components:

export function Callout({ type, className, children }: Props) {
  return (
    <div className={cn(
      "p-4 my-6 rounded-r-lg border-l-4",
      typeStyles[type],
      className  // Allow overrides from MDX
    )}>
      {children}
    </div>
  );
}

Guidelines

  • Keep MDX files focused on content - complex logic belongs in components
  • Use frontmatter for metadata, not configuration
  • Auto-discover components via import.meta.glob - avoid manual registries
  • Create custom MDX components for repeated content patterns
  • Type your frontmatter - it's your content schema
  • Organize content by category in directories
  • Name example files with Good/Bad suffix for clear intent

Common Mistakes

Don't: Import components in every MDX file

import { Button } from '@/components/ui/button';
import { Card } from '@/components/ui/card';

Do: Create domain-specific MDX components

import { ExampleComparison } from '@/components/mdx';
<ExampleComparison badKey="..." goodKey="..." />

Don't: Manual component registration

const components = {
  'forms-enter-submits-bad': EnterSubmitsBad,
  'forms-enter-submits-good': EnterSubmitsGood,
  // ... 50 more entries
};

Do: Auto-discovery with glob

const modules = import.meta.glob('./examples/**/*.tsx');

Advanced Code Highlighting with CodeHike

CodeHike provides rich code blocks with annotations, focus, diffs, and more.

Install:

npm install codehike

Configure in Vite:

// vite.config.ts
import { remarkCodeHike, recmaCodeHike } from 'codehike/mdx';

const chConfig = {
  components: { code: "Code" },
};

export default defineConfig({
  plugins: [
    mdx({
      remarkPlugins: [
        remarkGfm,
        remarkFrontmatter,
        [remarkMdxFrontmatter, { name: 'frontmatter' }],
        [remarkCodeHike, chConfig],
      ],
      recmaPlugins: [[recmaCodeHike, chConfig]],
      // ...
    }),
  ],
});

Usage in MDX:

```tsx
// !focus[1:3]
function Example() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(c => c + 1)}>{count}</button>;
}

CodeHike features:

  • Line highlighting and focus
  • Code annotations with callouts
  • Diff highlighting (additions/removals)
  • Scrollycoding (step-through tutorials)
  • File tabs and file trees

Advanced Patterns

For detailed implementation patterns, see REFERENCE.md.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.