astroadmin
v0.2.0
Published
Admin interface for Astro Content Collections - auto-generates forms from your Zod schemas
Maintainers
Readme
AstroAdmin
Admin interface for Astro Content Collections. Auto-generates forms from your Zod schemas.
Features
- Schema-driven forms - Auto-generates fields from
src/content/config.ts - Block editor - Visual editing for discriminated unions (page builders)
- Live preview - See changes in real-time via iframe
- Image uploads - Upload and manage images with alt text
- Git integration - Commit changes directly from the admin
- Collection management - Create and delete entries
Requirements
Before using AstroAdmin, ensure your project has:
- [ ] Node.js 18+
- [ ] Astro 4.0+ with
astro.config.mjsorastro.config.ts - [ ] Content Collections set up in
src/content/config.ts
your-astro-site/
├── astro.config.mjs ← Required
├── src/
│ └── content/
│ ├── config.ts ← Required (collection schemas)
│ └── pages/ ← Your collections
│ └── home.mdDon't have Content Collections? See the setup guide.
Installation
npm install astroadminUsage
# Start admin server (from your Astro project root)
npx astroadmin dev
# With options
npx astroadmin dev --port 3030 --project ./my-astro-siteThe server URL will be printed when it starts. Default credentials: admin / admin
Documentation
- Getting Started - Full setup guide
- Requirements - Detailed requirements
- Content Collections - Schema setup guide
- Configuration - Customization options
Astro Integration (optional)
For collections that aren't pages (e.g., testimonials, team members), AstroAdmin can preview them rendered inside their block components. Add the integration to your Astro config:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import astroadmin from 'astroadmin/integration';
export default defineConfig({
integrations: [astroadmin()],
});This injects a /component-preview/ route during development that renders your block components with the item being edited. Without this integration, non-page collections will show a 404 in the preview iframe.
Requirements:
- Block components in
src/components/blocks/following the naming convention{BlockType}Block.astro(e.g.,TestimonialsBlock.astro) - Fields referencing collections should use the naming convention
{collection}Ids(e.g.,testimonialIds)
Configuration (optional)
Create astroadmin.config.js in your project root:
export default {
preview: {
url: 'http://localhost:4321', // Astro dev server
},
auth: {
username: process.env.ADMIN_USER || 'admin',
password: process.env.ADMIN_PASSWORD || 'admin',
},
};Troubleshooting
"Invalid Astro project" error
This means AstroAdmin couldn't find the required files:
- Run from project root - Where
astro.config.mjsis located - Set up Content Collections - Create
src/content/config.ts
# Quick fix
mkdir -p src/content
touch src/content/config.tsSee Requirements for details.
Preview not loading
- Start your Astro dev server:
npm run dev - Check the preview URL in your config matches the Astro server
How it works
- Parses your
src/content/config.tsusing esbuild - Converts Zod schemas to JSON Schema via
zod-to-json-schema - Auto-generates form fields from the schema
- Detects discriminated unions for block-based editing
- Saves changes to markdown/JSON files in
src/content/
License
MIT
