A CMS makes publishing easier, but it does not automatically guarantee that every article has valid metadata.
You might save a Markdown post with a missing publication date, an unexpected category, an empty SEO description, or an image path that points to a file that was never committed. The editor can appear to work, yet the next deployment may render incorrect data, break a page, or fail during the build.
For an Astro website powered by Decap CMS, you can catch many of these problems before they reach production. Astro Content Collections and Zod provide a typed, build-time validation layer. Decap CMS handles the editing interface, while GitHub and your deployment pipeline decide when a validated change should be published.
In this guide, you will build a realistic reference implementation with a glob() content loader, a Zod frontmatter schema, matching Decap CMS fields, a blog route, an image-path check, and a simple GitHub Actions validation job.
The examples are designed for a Git-based, static Astro blog. They are not a drop-in migration script for a website with an established content structure. Audit your current field names and routes before changing them.
1. Why Content Validation Matters for a Git-Based CMS
Decap CMS is a convenient editor for Markdown content stored in Git. It can require fields and present select lists, but a successful CMS save is not equivalent to proof that the generated website will build correctly.
Consider these realistic mistakes:
- An article has a title but no
description, leaving an SEO component with incomplete input. - A
pubDatevalue cannot be parsed into a valid date. - An editor selects a category that the site does not support.
- A featured image points to
/images/uploads/old-cover.webp, which is missing from the relevant branch. - A post uses a different slug from the one expected by internal links.
- A newer field is added to the CMS, but the blog template and content schema do not recognize it.
Not all these errors are the same. Zod validates the shape and acceptable values of metadata; it does not automatically prove that image files exist or that internal links resolve. Those checks need separate logic.
The objective is to introduce small, independent safeguards so a bad draft becomes a clear review task instead of a production incident.
2. Understand Where Validation Fits
A typical editorial workflow has several stages:
Decap CMS editor
|
v
Save draft in Git branch / pull request
|
v
Astro loads Markdown with glob()
|
v
Zod validates frontmatter
|
+--- Invalid --> Report errors and fix draft
|
v
Build + image/link checks
|
v
Review deploy preview
|
v
Merge / publish --> Production deployment
In Decap CMS Editorial Workflow, a saved draft can remain in a separate Git branch until publication. In a static Astro site, the production build generally reflects the branch deployed by your hosting provider. That means a draft saved successfully in CMS is not necessarily available on the live website.

Figure 1: A Git-based publishing pipeline separates content editing, schema validation, build checks and publication.
Reference: Decap CMS Editorial Workflows.
3. Prepare a Safe Development Branch
Before changing a production project, inspect the existing repository and CMS configuration.
On Windows PowerShell:
cd D:\Web_DHN\duonghoangnam
git fetch origin
git branch --show-current
git status -sb
Check the current branch, pending pull requests, uncommitted edits, and existing content files. Do not replace a working content.config.ts or public/admin/config.yml without comparing their contents.
Identify these items first:
| Item | What to check |
|---|---|
| CMS collection folder | Where the Markdown files are saved |
| Frontmatter keys | date, pubDate, image, featuredImage, etc. |
| Existing content collection | Whether the site already uses src/content.config.ts |
| Published URL pattern | Whether routes are based on filenames or a slug field |
| CMS media settings | Where WebP files are stored and how URLs are generated |
| Build scripts | Whether npm run build already includes image optimization |
Do not rename existing content fields just to match a tutorial. Mapping a new schema to your current content is usually safer than changing dozens of published posts.
4. Define the Astro Content Collection
Modern Astro content collections use a loader and an optional schema. The built-in glob() loader can read Markdown files from a local directory.
Create or adapt src/content.config.ts:
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';
const blog = defineCollection({
loader: glob({
base: './src/content/blog',
pattern: '**/*.md',
}),
schema: z.object({
title: z.string().trim().min(10).max(140),
description: z.string().trim().min(40).max(200),
pubDate: z.coerce.date(),
updatedDate: z.coerce.date().optional(),
category: z.enum([
'AI Tools', 'Automation', 'Technology', 'Tutorials'
]),
author: z.string().trim().min(2),
featuredImage: z.string()
.startsWith('/images/uploads/')
.optional(),
draft: z.boolean().optional().default(false),
}),
});
export const collections = { blog };
The schema is deliberately specific: it requires a meaningful title, an SEO description, a parseable publication date, a supported category and an author.
Important: This example assumes the actual Markdown files use exactly these field names. If your CMS uses date, image, or another structure, adapt the schema instead of introducing a breaking rename. The length limits and allowed categories are editorial choices, not universal Astro requirements.
The featuredImage rule checks only the URL prefix. It does not check that the referenced WebP file exists; that is handled later.
Official references: Astro Content Collections and Content Loader API.
5. Create a Valid Markdown Entry
For a sample article at src/content/blog/valid-example.md, use matching YAML frontmatter:
---
title: "How to Validate Content Before Publishing"
description: "A practical guide to validating CMS frontmatter and preventing incomplete Astro article deployments."
pubDate: 2026-11-04
category: Tutorials
author: Duong Hoang Nam
featuredImage: /images/uploads/example-cover.webp
draft: false
---
Write the article body here.
The sample image is a placeholder. The build should be allowed to reference it only after the corresponding public/images/uploads/example-cover.webp file is present.
Keep article metadata in the frontmatter and article prose below the closing ---. In a typical Astro blog template, the template itself outputs the page’s H1 from title, so there is usually no need to add another H1 at the beginning of the Markdown body.
6. What a Validation Failure Looks Like
Now imagine a draft containing:
---
title: "Short"
description: "Too short"
category: Random Category
pubDate: not-a-date
author: ""
---
This entry violates multiple rules in the example schema. Astro can report content validation errors when it loads the collection for the build.
| Field | Why it fails | Safer correction |
|---|---|---|
title |
Fewer than 10 characters | Use a descriptive title |
description |
Fewer than 40 characters | Write a useful summary |
category |
Not one of the allowed options | Select a known category |
pubDate |
Cannot be parsed as a date | Use an ISO-style date |
author |
Empty after trimming | Provide the intended credit |
A failed build is desirable here: it prevents the invalid version from silently becoming a published page. But this also means a new strict schema can block deployment if older posts do not yet meet the rules. Audit and migrate old content on a separate branch before making strict checks mandatory.

Figure 2: Schema checks can catch invalid frontmatter before a site is built. The code printed inside the illustration is conceptual; use the verified TypeScript example in Section 4.
7. Align Decap CMS Fields with the Schema
Your Decap CMS collection should expose the same metadata keys expected by Astro. The following YAML is a collection example, not a replacement for your entire CMS configuration:
collections:
- name: blog
label: Blog
folder: src/content/blog
create: true
format: yaml-frontmatter
extension: md
slug: '{{slug}}'
fields:
- { label: Title, name: title, widget: string }
- { label: Description, name: description, widget: text }
- { label: Publish Date, name: pubDate, widget: datetime }
- { label: Updated Date, name: updatedDate, widget: datetime, required: false }
- label: Category
name: category
widget: select
options: [AI Tools, Automation, Technology, Tutorials]
- { label: Author, name: author, widget: string, default: 'Duong Hoang Nam' }
- { label: Featured Image, name: featuredImage, widget: image, required: false }
- { label: Draft, name: draft, widget: boolean, default: false }
- { label: Body, name: body, widget: markdown }
If your site already has a collections: list, merge the fields into the existing blog collection. Do not add a second collections: key, replace your GitHub backend, remove publish_mode: editorial_workflow, or change working media paths.
The CMS’s required and options settings help the editor create valid drafts, but they cannot replace server-side or build-time validation.
Reference: Decap CMS Configuration Options.
8. Generate Blog Pages from Validated Entries
A simple static route can use getCollection() and render() from Astro:
---
import { getCollection, render } from 'astro:content';
export async function getStaticPaths() {
const posts = await getCollection('blog', ({ data }) => data.draft !== true);
return posts.map((post) => ({
params: { slug: post.id },
props: { post },
}));
}
const { post } = Astro.props;
const { Content } = await render(post);
---
<h1>{post.data.title}</h1>
<p>{post.data.description}</p>
<Content />
Save this as src/pages/blog/[...slug].astro for this simplified example. A real production template should also supply your established layout, SEO metadata, breadcrumbs, accessible images and navigation.
Route compatibility is critical: This example uses post.id, typically derived from the Markdown file path. If the published site currently uses a custom slug frontmatter field or a different route generator, preserve that behavior. Changing a post URL without a redirect can break existing links and search traffic.
The draft flag is a second, independent concept from Decap CMS Editorial Workflow. A CMS draft branch is unpublished by Git workflow, whereas draft: true is metadata inside an entry that the route code may filter out. Do not confuse them.
9. Validate CMS Image Paths Separately
Astro will not automatically prove that a public/ image exists because a schema checks whether the frontmatter contains a string.
For a typical CMS setup:
media_folder: public/images/uploads
public_folder: /images/uploads
The repository file:
public/images/uploads/my-diagram.webp
should match the page URL:
/images/uploads/my-diagram.webp
An optional Node script can scan commonly formatted Markdown image links and featuredImage values, then test whether the corresponding file exists in the working branch. A runnable starter is included in this article’s download package as scripts/check-content-images.mjs.
This script is intentionally limited to ordinary local Markdown image syntax. It does not parse all MDX, HTML, URL encoding or complex Markdown variants. It should complement—not replace—your existing image pipeline and site preview checks.
For an Astro site that uses Sharp to create responsive WebP variants during the build, check that those generated files also exist after the image-processing stage finishes.
10. Validate Content with GitHub Actions
To catch bad content before publication, run validation on pull requests touching Markdown, images or the schema.
Example .github/workflows/validate-content.yml:
name: Validate blog content
on:
pull_request:
paths:
- 'src/content/**'
- 'src/content.config.ts'
- 'public/images/uploads/**'
- 'public/admin/config.yml'
- 'package.json'
- 'package-lock.json'
- '.github/workflows/validate-content.yml'
workflow_dispatch:
permissions:
contents: read
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: npm
- run: npm ci
- run: node scripts/check-content-images.mjs
- run: npm run build
This runs the local image-reference check and the site’s existing production build. The npm ci command depends on a committed, consistent package-lock.json.
The sample uses a read-only token and does not automatically merge or publish anything. Verify Node compatibility and the project’s build script before adopting it. If your existing CI already runs equivalent checks, extend that job instead of adding redundant workflows.
11. Test Failures Before Enforcing the Check
A good validation system should fail for the right reasons, not just pass on a valid sample.
Try the following on a separate branch:
| Test | Expected result |
|---|---|
| Valid frontmatter and existing files | Build succeeds |
Missing required pubDate |
Schema/build validation fails |
| Unexpected category | Schema/build validation fails |
| Empty description | Schema/build validation fails |
Missing /images/uploads/ file |
Optional image check fails |
| Draft not merged into production | Live site remains unchanged |
| Changed filename/slug | Manually verify intended route and redirects |
Remember that a schema can only enforce constraints you explicitly define. It cannot determine whether a technical claim is true, whether a title is misleading or whether the article provides enough original value.
12. Keep Editorial Rules and SEO Rules Separate
Schema validation is good at structured constraints:
- Does a required field exist?
- Is an input the expected type?
- Does a category belong to the allowed set?
- Does a path have an expected prefix?
Editorial review must handle qualitative concerns:
- Is the article accurate and current?
- Do code snippets work in the claimed version?
- Are images genuinely useful and relevant?
- Are external references trustworthy?
- Does the article overlap substantially with an existing tutorial?
- Are affiliate relationships disclosed appropriately?
A 100% passing CI pipeline does not mean a blog post is high quality. It only means the specified automated checks passed.
13. Safely Introduce Validation to an Existing Astro Blog
For an established website, a gradual rollout is safer than replacing existing structures in one commit.
Phase 1 — Inventory. Export or inspect current Markdown frontmatter and record all keys and value types. Check the real content.config.ts, route templates and Decap CMS configuration.
Phase 2 — Introduce the schema. Begin with common required fields and optional fields matching the existing content. Avoid aggressive length limits until older posts have been reviewed.
Phase 3 — Run the build. Use the project’s normal build script and investigate each validation error. Fix source metadata in a dedicated branch without changing public URLs.
Phase 4 — Add file checks. Check local image references and generated assets. Validate filename case and exact paths.
Phase 5 — Review and enforce. Once the CI job passes reliably and the deploy preview is correct, consider making the validation job a required check for content pull requests.
Do not delete draft branches, force-push over CMS work or change OAuth settings as a shortcut for making validation pass.
14. Common Pitfalls
Renaming date to pubDate without checking old posts
A schema’s property name must match the actual Markdown frontmatter. Rename only with an intentional migration and tests, or adapt the new schema.
Assuming valid image URLs mean images exist
A Zod string check does not access GitHub or inspect Cloudflare’s deployed assets. File existence is a different check.
Treating a successful CMS save as a production publish
With Editorial Workflow, save, review, merge and deploy are distinct steps. Verify the actual deployment status.
Changing filenames to match new schema IDs
Routes may depend on filenames, IDs or explicit slug properties. Preserve established URLs wherever possible.
Trusting an automated passing score as editorial approval
Schema checks reduce errors; they do not validate facts, accessibility, licensing or the usefulness of a tutorial.
15. Pre-Publish Content Validation Checklist
- Verify required frontmatter fields exist.
- Confirm the date and category formats match the Astro schema.
- Check the featured image and inline WebP files in the correct Git branch.
- Confirm the intended article slug has not changed unexpectedly.
- Run the image-reference checker when configured.
- Run the existing Astro production build.
- Review a deploy preview on desktop and mobile.
- Check headings, code, light/dark styles and internal links.
- Confirm Editorial Workflow status before publishing.
- Review the pull request diff for unintended changes.

Figure 3: A practical quality gate before an approved CMS draft reaches the published website.
16. Frequently Asked Questions
Does Astro support Zod-based content validation?
Yes. Astro Content Collections accept a Zod schema to validate entry data and provide TypeScript typing. Check the current docs for the API used by your installed Astro version.
Can Decap CMS prevent all invalid posts by itself?
No. CMS field widgets improve the editing experience, but build-time validation and preview checks address different failure modes.
Will adding a schema automatically fix broken image links?
No. It can check a path’s format, but an additional file check or build-time image pipeline is needed to verify file existence.
Do I need to replace my existing Astro blog routes?
No. If the existing routes already work, integrate validation into your current collection and maintain the established URL structure.
Can I validate an unpublished CMS draft?
Yes, if the pull request or preview build checks out the draft branch and runs the validation steps. Running only against the production branch will not validate unpublished changes.
Should all failing validation checks block publication?
Start with the checks that are reliably correct and high-impact. Treat false positives and legacy content systematically before making a job mandatory.
Final Thoughts
A Git-based publishing workflow becomes safer when saving content, validating metadata, checking assets, reviewing a preview, and publishing are treated as separate stages.
With Astro Content Collections and Zod, you can replace vague publishing surprises with specific, actionable validation errors. Decap CMS remains the editor; Astro and CI become the technical gatekeepers.
Use the sample code as a reference architecture. On an existing site, inventory the current content fields and routes first, introduce rules gradually, and test every change on a branch before touching production.
Continue Reading
- How to Build an Astro Blog with Decap CMS and Cloudflare Pages — The foundation for a Git-based Astro publishing workflow.
- Decap CMS Images Not Showing? How to Fix Draft 404s and Publishing Errors — Troubleshoot image paths and separate draft from production content.
- How to Find and Fix Broken Links in Astro with GitHub Actions (2026 Guide) — Add complementary link checks to your publishing pipeline.
Official Technical References
- Astro — Content Collections
- Astro — Content Loader API
- Astro — Images
- Decap CMS — Configuration Options
- Decap CMS — Editorial Workflows
- GitHub — Workflow Syntax
Technical disclosure: The example configuration and scripts are a reference implementation, not a claim that they have been installed, executed or validated against the live DuongHoangNam.com repository. File paths, schemas and routes must be adapted to the actual project. The article’s diagrams are explanatory illustrations, not screenshots of a completed production test.






