Skip to main content
Reggie Pangilinan
HomeBlogAbout
GitHubLinkedIn

© 2026 reggiepangilinan.com All rights reserved.

GitHubLinkedIn
Building a Git-to-Contentful Blog Draft Pipeline with…
←Back to Blog

Building a Git-to-Contentful Blog Draft Pipeline with GitHub Actions

Write in Markdown, commit local diagrams, and let GitHub Actions sync unpublished drafts to Contentful—then auto-archive once published.

December 2, 2026·Reggie Pangilinan·3 min read
Building a Git-to-Contentful Blog Draft Pipeline with GitHub Actions

I love Contentful for hosting structured blog content, webhooks, and image optimization—but when I'm actually writing a technical post, I'd much rather write in Markdown inside my editor (or pair with an AI coding agent) than click around a web form. ✍️

At the same time, I still want Contentful Studio to be the final gate before anything goes live: previewing the layout, attaching a featured image, and clicking Publish myself.

So I wired up a lightweight Git-to-Contentful pipeline using GitHub Actions and contentful-management that gives me the best of both worlds.


📁 1. Organizing Every Post in Its Own Folder

Each post lives in a self-contained folder named after its slug:

  • drafts/<slug>/index.md holds the YAML frontmatter (title, subtitle, slug, excerpt, publishDate, tags, author) and Markdown body.

  • drafts/<slug>/images/ holds any local diagrams or screenshots referenced with standard Markdown (![Alt text](./images/diagram.png)).

Keeping the Markdown and its images side-by-side means nothing gets orphaned in a giant global images folder—and when a post is published, moving the entire folder to published/<slug>/ keeps everything neatly grouped.

Git-to-Contentful Blog Pipeline
Git-to-Contentful Blog Pipeline

⚙️ 2. Markdown to Contentful Rich Text (With Automatic Image Uploads)

The core script, scripts/create-contentful-draft.js, parses the YAML frontmatter and converts headings (##, ###, ####), lists, blockquotes, horizontal rules, bold/italic/code marks, and hyperlinks into a valid Contentful Rich Text Document.

Two small details made a huge difference in day-to-day use:

  • Code-styled clickable links: Wrapping a link label in backticks keeps inline CODE formatting inside the INLINES.HYPERLINK node (even inside bold text or paths containing [slug]), and RichTextRenderer.tsx opens every link in a new tab.

  • Automatic local image uploads without duplicates: Whenever the parser sees a local Markdown image (![alt](./images/...)), it checks Contentful Media for an existing asset named <slug>--<filename>. If it's already there, it reuses it; otherwise it uploads, processes, and publishes the image asset and inserts a real embedded-asset-block node into the Rich Text body. 🖼️


🛡️ 3. Safe Upserts, Never Auto-Publishing

Running an automation script twice should never create duplicate blog posts or accidentally push half-finished edits live.

Here's how scripts/create-contentful-draft.js stays idempotent and safe:

  • Upsert by slug: It queries Contentful for an existing blogPost matching fields.slug. If none exists, it creates a new unpublished draft; if one exists, it merges fields in place (preserving Contentful-only fields like featuredImage).

  • Skip already-published entries by default: If sys.publishedVersion is set, the script skips the entry unless --force is passed—so routine runs never clobber edits made directly in Contentful Studio.

  • Never calls entry.publish(): Even with --force, updates land in Contentful's Changed draft state so you can inspect them in Contentful Preview before clicking Publish.


📦 4. Auto-Syncing Edits & Archiving Published Posts

The GitHub Actions workflow in .github/workflows/push-contentful-draft.yml ties the lifecycle together:

  • Push to `drafts/ on main**: Detects only added or modified files via git diff (even if you only updated an image inside images/) and upserts the matching index.md` as a draft.

  • Push to `published/ on main**: Syncs edits with --force` so updates to already-published posts stage cleanly in Contentful Preview as Changed drafts.

  • Auto-archiving via scripts/archive-published-drafts.js: Scans drafts/, checks which slugs are now published in Contentful, moves the entire drafts/<slug>/ folder to published/<slug>/, and commits the move with [skip ci] so it doesn't trigger an unnecessary rebuild.


✨ Wrapping Up

Now my writing loop is dead simple: write Markdown + drop in a diagram → merge a PR → preview in Contentful Studio → click Publish. Everything stays version-controlled in Git without giving up Contentful's editorial UI.

You can inspect the full scripts and workflow in the public repo at github.com/reggiepangilinan/mywebsite.

Keep Reading

Related Posts

December 3, 2026

Running a Full Next.js Blog on Free Tiers: A Contentful + Netlify Case Study

A data-backed case study breaking down Contentful Free, Netlify Free, and GitHub Free quotas (at the time of this writing), with real math on how many visitors, blog posts, and images a personal site can serve before ever paying a cent for infrastructure.

Next.jsContentful
December 3, 2026

Swiss Design Meets Punk Rock: How I Built an Automated Hero Poster System for My Blog

A plain-English look at the HTML/SVG poster generator behind my blog hero images, a quick intro to the Swiss International Style and punk-zine energy that inspired it, and how every poster flows from Git to Contentful.

Next.jsContentful
December 3, 2026

Adding AI-Powered Blog Search with Google Gemini in Next.js

How we added an intelligent, Gemini-powered search bar to a Next.js + Contentful blog—covering AI basics for non-specialists, why hybrid search beat Google Search Grounding and Vertex AI Search, real-world free-tier traffic estimates, and built-in cost guardrails.

Next.jsTypeScript
Topics
GitHub ActionsContentfulAutomationNext.jsDeveloper Experience

Share this article

Found this helpful? Copy the link or scan the QR code to share it.

←All blog posts