$npx -y skills add fusengine/agents --skill astro-contentExpert Astro Content Layer API — content.config.ts, glob/file loaders, custom loaders, getCollection, getEntry, render(), Zod schemas, MDX, Remark/Rehype plugins. Use when managing structured content, blog posts, or any typed data collections.
| 1 | # Astro Content Layer Expert |
| 2 | |
| 3 | Type-safe content management with loaders, Zod schemas, and the unified Content Layer API. |
| 4 | |
| 5 | ## Agent Workflow (MANDATORY) |
| 6 | |
| 7 | Before ANY implementation, use `TeamCreate` to spawn 3 agents: |
| 8 | |
| 9 | 1. **fuse-ai-pilot:explore-codebase** - Check existing collections, loaders, and content structure |
| 10 | 2. **fuse-ai-pilot:research-expert** - Verify latest Content Layer docs via Context7/Exa |
| 11 | 3. **mcp__context7__query-docs** - Get loader and schema examples |
| 12 | |
| 13 | After implementation, run **fuse-ai-pilot:sniper** for validation. |
| 14 | |
| 15 | --- |
| 16 | |
| 17 | ## Overview |
| 18 | |
| 19 | ### When to Use |
| 20 | |
| 21 | - Managing blog posts, docs, or product descriptions in Markdown/MDX |
| 22 | - Fetching content from a CMS, API, or database with type safety |
| 23 | - Needing TypeScript autocomplete for frontmatter fields |
| 24 | - Migrating from Astro 4 legacy content collections |
| 25 | |
| 26 | ### Why Content Layer API |
| 27 | |
| 28 | | Feature | Benefit | |
| 29 | |---------|---------| |
| 30 | | `src/content.config.ts` | Single config file at project root | |
| 31 | | Built-in loaders | `glob()` and `file()` for local files | |
| 32 | | Custom loaders | Fetch from any external source | |
| 33 | | Zod 4 schemas | Full TypeScript type safety | |
| 34 | | `astro sync` | Generates types from collections | |
| 35 | |
| 36 | --- |
| 37 | |
| 38 | ## Core Concepts |
| 39 | |
| 40 | ### Config File Location |
| 41 | |
| 42 | The config file moved from `src/content/config.ts` to `src/content.config.ts` in Astro 5+. |
| 43 | |
| 44 | ### Collection Types |
| 45 | |
| 46 | | Loader | Use Case | |
| 47 | |--------|----------| |
| 48 | | `glob()` | Multiple files in a directory (MD, MDX, JSON, YAML) | |
| 49 | | `file()` | Single JSON/YAML file with multiple entries | |
| 50 | | Custom | Remote API, database, or any async data source | |
| 51 | |
| 52 | ### Key APIs |
| 53 | |
| 54 | | API | Description | |
| 55 | |-----|-------------| |
| 56 | | `getCollection(name)` | Fetch all entries in a collection | |
| 57 | | `getEntry(name, id)` | Fetch a single entry by ID | |
| 58 | | `render(entry)` | Render a content entry to HTML + headings | |
| 59 | | `defineCollection()` | Define a collection with loader and schema | |
| 60 | |
| 61 | --- |
| 62 | |
| 63 | ## Reference Guide |
| 64 | |
| 65 | | Need | Reference | |
| 66 | |------|-----------| |
| 67 | | Overview & concepts | [overview.md](references/overview.md) | |
| 68 | | Config file setup | [config.md](references/config.md) | |
| 69 | | Glob, file, custom loaders | [loaders.md](references/loaders.md) | |
| 70 | | getCollection / getEntry | [querying.md](references/querying.md) | |
| 71 | | render() + headings | [rendering.md](references/rendering.md) | |
| 72 | | MDX + Remark/Rehype | [mdx.md](references/mdx.md) | |
| 73 | | Blog collection example | [templates/blog-collection.md](references/templates/blog-collection.md) | |
| 74 | | Custom remote loader | [templates/custom-loader.md](references/templates/custom-loader.md) | |
| 75 | |
| 76 | --- |
| 77 | |
| 78 | ## Best Practices |
| 79 | |
| 80 | 1. **Always define schemas** — Never skip Zod validation |
| 81 | 2. **Run `astro sync`** — After changing `content.config.ts` |
| 82 | 3. **Use `glob()` for local files** — Supports MD, MDX, JSON, YAML, TOML |
| 83 | 4. **Custom loaders for remote data** — CMS, REST API, GraphQL |
| 84 | 5. **`render()` for MDX** — Returns `Content` component + headings array |