Astro and Decap CMS work together by adding two static files to public/admin/: an index.html that loads the Decap app and a config.yml that maps editor fields to your content collection folders. Editors log in at /admin/, and every save becomes a Git commit to Markdown files in your repository, which triggers a normal static rebuild. There’s no database and no server to run.
This guide sets up Decap CMS on an Astro 7 site with content collections, covers the backend choices, and lists the limits you should know before handing it to editors.
Key Takeaways
- Decap CMS is a single-page app you serve from
public/admin/; Astro just copies it into the build.config.ymldescribes collections whosefolderpoints atsrc/content/<collection>/.- Keep Decap fields and your Zod schema in
src/content.config.tsin sync, or builds fail on save.- The
githubbackend needs an OAuth provider;git-gatewayrelies on Netlify’s identity service.local_backend: trueplusnpx decap-serverlets you edit local files without logging in.
What Decap CMS is and when it fits
Decap CMS (formerly Netlify CMS) is an open-source, Git-based content editor. It runs entirely in the browser: it reads your repository through a Git host’s API, shows editors a form for each entry, and commits the changes back. Your Astro site keeps reading plain Markdown files, so nothing about your content collections changes.
It fits well when:
- The site is static and content lives in Markdown or MDX in the repo already.
- A small number of editors need a form instead of a code editor.
- You want content history, review and rollback through Git.
It fits less well when editors need live visual editing, scheduled publishing, complex relational content or many simultaneous editors. For those, an API-based CMS like Sanity or Storyblok is usually a better choice; the headless CMS guide compares the options, and Markdown or a CMS helps you decide whether you need one at all.
Step 1: Add the Decap admin page
Create public/admin/index.html. Files in public/ are copied to the build unchanged, so this becomes /admin/index.html on your site.
<!-- public/admin/index.html -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="robots" content="noindex" />
<title>Content Manager</title>
</head>
<body>
<script src="https://unpkg.com/decap-cms@^3.0.0/dist/decap-cms.js"></script>
</body>
</html>
Decap looks for config.yml in the same folder by default. The noindex tag keeps the admin shell out of search results. If you prefer not to load from a CDN, install decap-cms-app from npm and bundle it yourself, but the script tag is the quickest working setup.
Step 2: Write config.yml for your content collection
Assume an Astro blog collection defined like this:
// 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', base: './src/content/blog' }),
schema: z.object({
title: z.string(),
description: z.string(),
pubDate: z.coerce.date(),
heroImage: z.string().optional(),
tags: z.array(z.string()).default([]),
draft: z.boolean().default(false),
}),
});
export const collections = { blog };
The matching Decap config maps one field to each schema key:
# public/admin/config.yml
backend:
name: github
repo: your-username/your-site
branch: main
media_folder: public/images/blog
public_folder: /images/blog
collections:
- name: blog
label: Blog posts
folder: src/content/blog
create: true
slug: '{{slug}}'
extension: md
format: frontmatter
fields:
- { label: Title, name: title, widget: string }
- { label: Description, name: description, widget: text }
- { label: Publish date, name: pubDate, widget: datetime, format: 'YYYY-MM-DD' }
- { label: Hero image, name: heroImage, widget: image, required: false }
- { label: Tags, name: tags, widget: list, default: [] }
- { label: Draft, name: draft, widget: boolean, default: false }
- { label: Body, name: body, widget: markdown }
A few things in this file matter for Astro:
foldermust match thebaseof yourglob()loader, relative to the repo root.media_folderis where uploads are committed;public_folderis the URL written into frontmatter. Usingpublic/keeps image paths as plain strings, which matchesz.string()in the schema.- The field named
bodyis special: Decap writes it as the Markdown content below the frontmatter. format: 'YYYY-MM-DD'on the date widget writes a plain date thatz.coerce.date()parses.
Step 3: Choose a Decap CMS backend for Astro
The backend decides how editors log in and how Decap talks to Git.
| Backend | How login works | Good for |
|---|---|---|
github |
GitHub OAuth through an OAuth provider you configure | Editors with GitHub accounts, any static host |
gitlab |
GitLab OAuth (PKCE flow available) | Sites hosted on GitLab |
git-gateway |
Netlify’s identity service proxies Git access | Sites on Netlify where editors shouldn’t need a Git account |
bitbucket, gitea |
That host’s OAuth | Sites hosted there |
The github backend needs a small OAuth handler, because the browser can’t hold your OAuth client secret. On Netlify, the built-in OAuth provider handles this once you add a GitHub OAuth app in site settings. On Cloudflare, Vercel or elsewhere, you deploy a community OAuth proxy (several exist as small Workers or functions) and point Decap at it with base_url and auth_endpoint in the backend block.
git-gateway depends on Netlify’s identity product. Check Netlify’s current documentation for its status before you build editor onboarding around it.
Step 4: Edit content locally without logging in
For development, Decap can write straight to your local files through a small proxy server:
# public/admin/config.yml (top level)
local_backend: true
Then run two processes:
npx decap-server
npm run dev
Open http://localhost:4321/admin/. Decap detects the local proxy and saves to src/content/blog/ on disk, and Astro’s dev server reloads the page with the new entry. In production, local_backend is ignored when the proxy isn’t reachable, so it’s safe to leave in.
Using MDX with Decap CMS and Astro
Decap edits Markdown. It can save files with an .mdx extension (extension: mdx with format: frontmatter), but its rich-text editor doesn’t understand JSX. If an editor opens an MDX file that contains <Callout> or an import, the visual editor may mangle it.
Practical options:
- Keep editor content in
.md. Put components in layouts instead of in the body. This is the most reliable setup. - Use MDX for developer-written pages only. Point Decap at a Markdown collection and keep MDX in another folder.
- Register custom editor components with
CMS.registerEditorComponentfor one or two shortcodes your editors need. This takes JavaScript work and testing.
The content collections guide covers splitting content into multiple collections.
Editorial workflow and previews
Decap has an optional editorial workflow that saves drafts as pull requests instead of committing to main:
# public/admin/config.yml (top level)
publish_mode: editorial_workflow
Editors then see Drafts, In Review and Ready columns. Moving an entry to Ready and publishing merges the pull request. If your host builds preview deployments for pull requests (Cloudflare Pages, Netlify and Vercel all do), each draft gets a real preview URL of the Astro site.
Decap’s own preview pane renders entries with its default styles, not your Astro components. You can register preview templates and stylesheets with CMS.registerPreviewTemplate and CMS.registerPreviewStyle, but many teams rely on host preview URLs instead because they show the real site.
Common Astro and Decap CMS problems
| Problem | Cause | Fix |
|---|---|---|
/admin/ shows a blank page |
config.yml has a YAML error |
Check the browser console; Decap logs the parse error |
| Build fails after an editor saves | A field doesn’t match the Zod schema | Align widget types, required: false and schema .optional() |
| Images break after upload | public_folder doesn’t match the served path |
Use /images/blog with media_folder: public/images/blog |
| Login loops on GitHub | OAuth provider URL or callback is wrong | Recheck base_url, auth_endpoint and the OAuth app callback |
| New posts don’t appear on the site | Site hasn’t rebuilt | Confirm the host builds on every push to the branch |
| Dates shift by a day | Datetime widget writes a time zone | Use format: 'YYYY-MM-DD' and z.coerce.date() |
The frontmatter does not match schema fix explains the exact error Astro shows when an edited file fails validation.
Is Decap CMS the right Astro CMS for you?
Decap’s strengths are that it’s free, open source, keeps content in your repo and adds nothing to your runtime. Your Astro site stays fully static, which suits every Komal theme: they ship content as Markdown collections, so the Astro blog and editorial themes can take a Decap config with the fields above adjusted to each theme’s schema.
Its weaknesses are a dated editing experience compared with commercial CMSs, a preview pane that isn’t your real site, and authentication setup that depends on your host. If those are dealbreakers, look at a Git-based alternative such as Keystatic or TinaCMS, or an API-based CMS.
Read the official Decap CMS docs for every widget option, and Astro’s Decap CMS guide for the integration overview.
FAQ
Is Decap CMS free to use with Astro?
Yes. Decap CMS is open source under the MIT licence and costs nothing. You may pay for whatever handles authentication or hosting, but many static hosts have free tiers that cover small sites.
Does Decap CMS work without Netlify?
Yes. Use the github, gitlab, bitbucket or gitea backend and provide an OAuth handler for that Git host. The site itself can be on Cloudflare Pages, Vercel, GitHub Pages or any static host.
Can Decap CMS edit Astro content collections?
Yes. Point each Decap collection’s folder at the collection’s directory under src/content/ and define one field per schema key. Decap writes Markdown with frontmatter, which Astro’s glob() loader reads as usual.
Does Decap CMS support MDX in Astro?
Partly. It can save .mdx files, but its rich-text editor treats the body as Markdown and doesn’t render or protect JSX components. Keep editor-facing content in .md and reserve MDX for pages developers maintain.
How do I add Decap CMS to an existing Astro theme?
Add public/admin/index.html and public/admin/config.yml, then copy the field names from the theme’s src/content.config.ts into the config. Test with local_backend: true and npx decap-server before connecting a production backend.