Getting Started
- Install the package
Terminal window npm install astronaut-cms @astrojs/react react react-dom zodTerminal window pnpm add astronaut-cms @astrojs/react react react-dom zod - Add the integration to your Astro config
astro.config.ts import { defineConfig } from "astro/config";import mdx from "@astrojs/mdx";import react from "@astrojs/react";import cms from "astronaut-cms";export default defineConfig({integrations: [mdx(), react(), cms()],}); - Define your content collections
Create a
src/content.config.tsfile using Astro’s standard content collection API:src/content.config.ts import { defineCollection } from "astro:content";import { glob } from "astro/loaders";import { z } from "astro/zod";const blog = defineCollection({loader: glob({ pattern: "**/*.{md,mdx}", base: "src/content/blog" }),schema: ({ image }) =>z.object({title: z.string(),description: z.string(),date: z.coerce.date(),draft: z.boolean().default(false),cover: image().optional(),}),});export const collections = { blog }; - Start the dev server and open the admin panel
Terminal window npm run devNavigate to
http://localhost:4321/adminto access the CMS admin panel.
Deploying
Section titled “Deploying”astro dev edits the working tree and needs no sign-in, so everything above works with no further setup.
A deployed CMS is different: it holds the repository session on the server, so it needs two things.
- An SSR adapter
@astrojs/node,@astrojs/cloudflare,@astrojs/vercel,@astrojs/netlify— whichever suits your host. The rest of your site can stay static. The build fails with a message if one is missing, unlessadmin: falseleaves the admin out of the build. - A Git backend
A GitHub App or GitLab application, whose client id goes in
astro.config.tsand whose secret goes in the environment asASTRONAUT_CMS_GITHUB_CLIENT_SECRET(or..._GITLAB_...).That is the only secret. The session cookie’s key is derived from it, so there is nothing to generate, seed or keep in sync.
Next Steps
Section titled “Next Steps”- Learn how to configure the integration.
- Learn how to define content collections.
- Learn how to create custom MDX block components.
- Learn how to deploy with a Git backend.
