roninforge/roninforge-astro/astro-migrate-to-content-layer

Claude Code and agent skill by roninforge/roninforge-astro

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Stage-by-stage migration of an Astro 4 collection to the Astro 5+ Content Layer: move src/content/config.ts to src/content.config.ts (Astro 6 removed the old path), replace type:'content' / type:'data' with loader:glob() or loader:file() from astro/loaders, replace getEntryBySlug with getEntry, replace post.render() with render(post) imported from astro:content, replace entry.slug with entry.id, drop Astro.glob in favour of getCollection on a glob loader. Includes before/after diffs and a checklist for each numbered anti-pattern. Pairs with astro-content-layer and astro-anti-patterns rules.

Install

npx vskill@latest install roninforge/roninforge-astro/astro-migrate-to-content-layer

SKILL.md

The same SKILL.md was published earlier as roninforge/roninforge-astro/astro-migrate-to-content-layer.

Migrate Astro 4 collections to the Content Layer

When to use

Run when:

  • The codebase still has src/content/config.ts
  • Any collection uses type: 'content' or type: 'data'
  • Any code calls getEntryBySlug, entry.render(), entry.slug, or Astro.glob

Target: astro ^6.3.3. Source pages: https://docs.astro.build/en/guides/upgrade-to/v5/ and https://docs.astro.build/en/guides/content-collections/

Stage 1: bump versions

diff
// package.json
{
"dependencies": {
- "astro": "^4.16.19"
+ "astro": "^6.3.3"
},
"devDependencies": {
- "@astrojs/tailwind": "^5.1.0",
- "zod": "^3.23.0"
+ "@tailwindcss/vite": "^4.3.0",
+ "tailwindcss": "^4.3.0",
+ "zod": "^4.4.3"
},
"engines": {
- "node": ">=18"
+ "node": ">=22.12.0"
}
}

Run pnpm install (or your manager). Run astro check and accept that it will print errors; the next stages fix them.

Stage 2: move the config file

bash
git mv src/content/config.ts src/content.config.ts

Astro 6 no longer reads src/content/config.ts (anti-pattern #47).

Stage 3: replace type with loader

diff
// src/content.config.ts
-import { defineCollection, z } from 'astro:content'
+import { defineCollection, z } from 'astro:content'
+import { glob, file } from 'astro/loaders'
export const collections = {
blog: defineCollection({
- type: 'content',
+ loader: glob({ pattern: '**/*.md', base: './src/content/blog' }),
schema: z.object({ title: z.string(), publishedAt: z.date() }),
}),
authors: defineCollection({
- type: 'data',
+ loader: file('src/content/authors.json'),
schema: z.object({ id: z.string(), name: z.string() }),
}),
}

Stage 4: rename slug to id, drop entry.render

diff
---
-import { getEntryBySlug } from 'astro:content'
-const post = await getEntryBySlug('blog', Astro.params.slug)
-const { Content } = await post.render()
+import { getEntry, render } from 'astro:content'
+const post = await getEntry('blog', Astro.params.id)
+if (!post) return new Response('Not found', { status: 404 })
+const { Content } = await render(post)
---
<Content />

For the parameter file rename: src/pages/blog/[slug].astro should become src/pages/blog/[...id].astro if the URL still needs to accept slashes; otherwise src/pages/blog/[id].astro.

Stage 5: replace Astro.glob

diff
---
-const posts = await Astro.glob('../content/blog/*.md')
+import { getCollection } from 'astro:content'
+const posts = await getCollection('blog')
---
{posts.map(post => (
- <a href={`/blog/${post.frontmatter.slug}`}>{post.frontmatter.title}</a>
+ <a href={`/blog/${post.id}`}>{post.data.title}</a>
))}

Note that the property changed from post.frontmatter.x to post.data.x.

Stage 6: drop hybrid output

diff
// astro.config.mjs
export default defineConfig({
- output: 'hybrid',
+ output: 'static',
+ // OR: output: 'server' if most routes were SSR
})

If most routes were SSR, use output: 'server' and add export const prerender = true to the static ones. If most were static, use output: 'static' and add export const prerender = false to the SSR ones (anti-pattern #11).

Stage 7: switch from @astrojs/tailwind to @tailwindcss/vite

diff
// astro.config.mjs
-import tailwind from '@astrojs/tailwind'
+import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
- integrations: [tailwind()],
+ vite: { plugins: [tailwindcss()] },
})
diff
/* src/styles/global.css */
-@tailwind base;
-@tailwind components;
-@tailwind utilities;
+@import "tailwindcss";

Delete tailwind.config.js (Tailwind 4 reads CSS-only config).

Stage 8: rename ViewTransitions to ClientRouter

diff
---
-import { ViewTransitions } from 'astro:transitions'
+import { ClientRouter } from 'astro:transitions'
---
-<ViewTransitions />
+<ClientRouter />

Stage 9: switch zod imports inside src/actions/

diff
// src/actions/index.ts
import { defineAction } from 'astro:actions'
-import { z } from 'zod'
+import { z } from 'astro:schema'

Stage 10: re-run astro check + astro build

bash
pnpm astro check
pnpm astro build

If you see "could not prerender": that page still uses request-time data. Either move the data to a build-time fetch, or set prerender = false.

Per-anti-pattern checklist

PatternWhat to do
#6 getEntryBySlugRename to getEntry
#7 Astro.globReplace with getCollection on a glob() loader
#8 entry.render()Replace with render(entry) from astro:content
#9 type:'content'Replace with loader: glob(...) or loader: file(...)
#10 entry.slugRename to entry.id
#11 output:'hybrid'Pick static or server, set prerender per-route
#16 @astrojs/tailwindSwitch to @tailwindcss/vite in vite.plugins
#23 ViewTransitionsRename to ClientRouter
#45 node 18Bump engines to >=22.12.0
#46 zod in actionsImport from astro:schema
#47 src/content/config.tsMove to src/content.config.ts

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
5

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/roninforge/roninforge-astro/astro-migrate-to-content-layer/badge)](https://verified-skill.com/skills/roninforge/roninforge-astro/astro-migrate-to-content-layer)

Something wrong with this skill or its page? Tell us.