The repo is the system of record.
How to use Notion as a CMS without letting it become your database: writers keep drafting in Notion, and every publish lands in git as a reproducible build. Why the repository, not a CMS admin, should be the source of truth.
- Published
- 08 Jul 2025
- Length
- 6 min read
- Roles
- Architecture, Growth
- From the work on
- Ema
Ask most teams that run a marketing site a simple question, what is live right now and who changed it last, and watch how long the answer takes.
Marketing pages live in one CMS. Developer docs live somewhere else. A handful of landing pages are hardcoded because someone needed them on a Friday. Each tool has its own admin, its own permissions, and its own idea of "published". None of them has a diff.
This is how to use Notion as a CMS, build on top of it, and replace all of that with one rule. Writers work in Notion, because that is where they already write. But nothing goes live from Notion. Every publish becomes a commit: a content snapshot, the code that renders it, and the config that routes it, in one repository. The repo is the system of record. Notion is the editor.
The problem, more precisely
A CMS admin is a mutable database with a web form in front of it. Fine for editing, terrible for everything after. No review before a change is live, no two versions side by side, and rollback means someone remembering what the text used to say. Worse, the deployed site depends on a remote database at build time, so the same commit can produce two different sites a week apart.
Version control solved all of this for code a long time ago. So the goal was never to build a CMS. It was to make content behave like code without making writers behave like engineers.
The pipeline
Five stages, each one a pure function of the one before.
Fetch. Notion databases map to collections: docs, blog, changelog. Each page carries the properties the pipeline needs: slug, status, publish date, authors. The API paginates blocks and nested blocks need their own request, so the fetcher walks the tree recursively and skips pages whose last_edited_time has not changed since the last snapshot.
Normalize. Notion's block shapes are irregular: rich text is an array of annotated spans, headings come in three types, nested lists hang off their parent item. The normalizer turns all of it into a small, typed JSON AST. Everything downstream only knows about the AST, so if Notion changes a shape, one file changes.
Transform. The AST becomes MDX for docs and marketing pages, or a React tree directly where MDX would only be in the way. Components in the AST map to components in the site's library, so a Notion callout renders with the same Callout the engineers use by hand.
Commit. The generated content is written into the repository under a content/ directory, alongside a manifest of slugs, redirects and image references. The commit message carries the Notion page id and the editor who triggered it.
Build and deploy. The same Next.js build that runs for a code change runs for a content change. Static pages are generated from the snapshot. Nothing fetches Notion at request time, so a Notion outage cannot take the site down.
Making it instant
Writers do not wait for a nightly job. When a page's status flips to Published, a webhook hits a small endpoint which enqueues a rebuild. Polling on last_edited_time covers databases that do not emit events. Jobs coalesce: ten edits inside a minute produce one build, not ten. The job fetches only what changed, regenerates the snapshot, commits to a content branch, and the ordinary deploy pipeline takes over. The writer presses Publish and the page appears. The engineer sees a commit with the writer's name on it.
A typed block schema
The AST is the contract between the half of the system that knows about Notion and the half that knows about React. Keeping it small is the whole point.
type RichText = {
text: string;
bold?: boolean;
italic?: boolean;
code?: boolean;
href?: string;
};
type Block =
| { type: "heading"; level: 2 | 3 | 4; id: string; text: RichText[] }
| { type: "paragraph"; text: RichText[] }
| { type: "list"; ordered: boolean; items: Block[][] }
| { type: "code"; language: string; code: string; caption?: string }
| { type: "callout"; tone: "info" | "warning"; children: Block[] }
| { type: "image"; src: string; width: number; height: number; alt: string }
| { type: "table"; hasHeader: boolean; rows: RichText[][][] }
| { type: "divider" };
type Page = {
notionId: string;
slug: string;
title: string;
status: "draft" | "published";
publishedAt: string | null;
lastEditedAt: string;
blocks: Block[];
};The normalizer is a switch over Notion's block types. Anything it does not recognise is dropped, logged, and listed in the build summary, so a writer finds out that an embed did not make it rather than discovering a hole in the page.
import type { BlockObjectResponse } from "@notionhq/client/build/src/api-endpoints";
export function normalize(block: BlockObjectResponse, children: Block[]): Block | null {
switch (block.type) {
case "paragraph":
return { type: "paragraph", text: richText(block.paragraph.rich_text) };
case "heading_2":
return { type: "heading", level: 2, id: block.id, text: richText(block.heading_2.rich_text) };
case "code":
return {
type: "code",
language: block.code.language,
code: block.code.rich_text.map((t) => t.plain_text).join(""),
};
case "callout":
return { type: "callout", tone: "info", children };
case "divider":
return { type: "divider" };
default:
report.unsupported(block.type, block.id);
return null;
}
}The awkward parts
Images
Notion serves uploaded files through signed URLs that expire after about an hour. If you put those URLs in a page, the page breaks before lunch. So the pipeline rehosts every image at snapshot time: download, hash the bytes, upload to your own storage under the hash, and rewrite the reference. Hashing gives stable URLs, free deduplication, and immutable cache headers. It also records intrinsic width and height so the renderer can reserve space and nothing shifts while images load.
async function rehost(url: string): Promise<ImageRef> {
const res = await fetch(url); // signed, short-lived
const bytes = new Uint8Array(await res.arrayBuffer());
const hash = createHash("sha256").update(bytes).digest("hex").slice(0, 16);
const key = `content/${hash}.${extensionFor(res.headers.get("content-type"))}`;
if (!(await storage.exists(key))) {
await storage.put(key, bytes, {
cacheControl: "public, max-age=31536000, immutable",
});
}
const { width, height } = imageSize(bytes);
return { src: `${CDN_ORIGIN}/${key}`, width, height };
}Slugs and redirects
The slug is a Notion property, and the pipeline validates it: lowercase, kebab-case, unique within its collection. A bad slug fails the job with a message that names the page. When a slug changes, the snapshot diff shows the old and new pair, and the pipeline appends a permanent redirect to a JSON file that Next.js reads at build. Redirects are versioned with everything else, so a renamed page never produces a dead link, and git log shows exactly when the rename happened.
[
{ "source": "/docs/getting-started", "destination": "/docs/quickstart", "permanent": true },
{ "source": "/blog/launch", "destination": "/blog/introducing-the-product", "permanent": true }
]Previews and draft mode
Pages with status Draft are fetched and normalized but written to a separate snapshot that never enters the production build. Next.js draft mode renders them on a preview URL behind authentication. Writers get the preview link from a property on the Notion page. Same renderer, same components, same layout as the published page, which is the only kind of preview worth having.
Why git beats a CMS admin
- Diff. A content change is a pull request, readable line by line.
- Review. Content goes through the same review as code when it needs to, and skips it when it does not.
- Rollback.
git revert. No admin UI, no restoring from a backup, no remembering. - Audit.
git log -- content/docs/quickstart.mdxanswers who, when and why for the life of the page. - Reproducibility. Any commit rebuilds exactly the site that existed at that commit. No external state.
- Parity. Staging and production build from the same snapshot; only environment config differs.
What I'd still use a CMS for
This is a narrowing of content management, not a rejection of it. Some things a real CMS does better than a document tool feeding a repository.
- Structured content with relations and a query layer: product catalogues, pricing tables, anything you need to filter at runtime.
- Content that changes faster than a build cycle: status pages, live pricing, inventory.
- Localisation at scale, where translators need a workflow, not a page tree.
- Fine-grained roles and multi-step approvals for large non-technical teams.
- Personalisation decided at request time.
Notion is an excellent editor and a mediocre database. The pipeline uses it for the first and refuses to let it be the second.
What I'd carry forward
- Pick the editor people already use and build the system around it, rather than asking them to learn yours.
- Normalize to a small typed AST once. Every other stage gets simpler.
- Treat images, slugs and redirects as first-class outputs of the pipeline, not afterthoughts.
- Make the build independent of the source at request time. The site should survive the editor being down.
- Put every published state in git. If you cannot
git logit, you do not own it.