TL;DR — Writing directly to Sanity via `bun run publish post.md` — no Studio, no git commit, no manual redeploy. Webhook handles the rebuild.
The Sanity Studio is nice, but sometimes I want to write in vim and ship a post without opening a browser tab. So I built a CLI.
How it works
The CLI reads a markdown file with frontmatter, converts the body to portable text, and creates a document in Sanity via the Content Lake API.
bun run publish drafts/my-post.mdBehind the scenes:
- Frontmatter maps directly to the post schema
- Markdown body becomes portable text blocks (paragraphs, headings, code fences, links)
- The existing Sanity webhook fires on document creation
- GitHub
repository_dispatchtriggers CI - Cloudflare Pages redeploys in ~90 seconds
Why not just commit MDX?
I could — Astro content collections handle MDX fine. But Sanity is the source of truth now, and going through the Studio (or its API) means every post shows up in the Studio's edit view. If I need to fix a typo three weeks later, I don't have to remember whether it lives in git or in Sanity. It's all in Sanity.
The tradeoff: markdown gets a lossy conversion to portable text on the way in. Simple inline formatting (bold, italic, code, links) survives. Anything exotic doesn't. For engineering posts this has been fine.