Headless CMS
taelee.dev on Sanity
This site, moved from a TypeScript content file onto Sanity in a week: a typed content model, GROQ with explicit projections, pages cached at the edge and expired by tag when a publish webhook fires, and draft preview on the real pages. The same shape as a Next.js-plus-Contentful marketing platform, at one-person scale.
Year2026
TimelineOne week, October 2026
RoleEverything: model, Studio, migration, site
Why
Before this, every word and image on the site lived in one TypeScript file. Changing a sentence meant a commit, a push and a two-minute build. That is fine for one person and wrong for anyone else, and it is the opposite of how a marketing site has to work, where the people who own the words are not the people who own the deploy.
The goal was the shape a content-driven site at scale actually has: content in a headless CMS, edited in a Studio on my own domain, pages fully static at the edge, and a publish that refreshes exactly the pages that used the changed content in under a second with no build. Unpublished drafts previewable on the real pages, beside the editor, with click-to-edit. Nothing about the site's performance was allowed to change.
The content model
Five document types, named for what the content is rather than how it renders: site settings and a hero as singletons, then projects, work experience and social links. Singletons are a Studio concern, not a schema flag: the document is pinned to a fixed id in the desk structure, hidden from the create menu, and stripped of delete and duplicate. The fixed id makes the read query cheap and the migration idempotent.
Bodies are Portable Text, Sanity's JSON block model, restricted in the schema to normal paragraphs with strong, emphasis and link marks. An editor cannot paste in a heading or a table, and the frontend renders the blocks through a components map, so the design owns the markup. Validation lives in the schema and blocks publish: slugs lowercase and hyphenated, alt text required on every image, display order an integer, every link an absolute URL, a site path or a mailto.
Sections, figures and links are embedded objects because one document owns them. That is the single biggest modelling decision that changes at multi-site scale: pricing tables, calls to action and customer quotes become references, so one edit updates every page that uses them, and the publish webhook has to expire every referencing document.
The read path
Every GROQ query has an explicit projection. The page receives only the fields it renders, so a schema change cannot leak a new field into the HTML. Optional arrays are coalesced to empty arrays so components never null-check, and image assets are dereferenced to their URL, dimensions and the low-quality preview Sanity computes on upload, which becomes the blur placeholder.
Fetches go through Next's data cache with no expiry and a tag per document type read, plus a tag per project slug. Sanity's own CDN is switched off on this client: Next is the cache, and when a tag expires the page should read the origin, not a second cache with its own staleness. The home page and every project page are prerendered at build; a project published after the build renders on its first request and is cached from then on.
The publish path
Pressing Publish in the Studio fires a GROQ-powered webhook whose projection is just the document type and slug, signed with an HMAC over a timestamp and the body. The receiving route verifies the signature against a shared secret, waits a moment for Sanity's eventual consistency, then expires the matching tags with immediate expiry rather than stale-while-revalidate, so the next request blocks and renders fresh. That is what a publish button should feel like.
Tags rather than paths because the home page shows every project's card, so editing one project must expire the home page too. Tagging both with the document type does that in one call. Path-based revalidation would need the webhook to know every URL that renders a given document, which is exactly the coupling a multi-site estate cannot afford. The check that proves it: edit, publish, reload, see the change, with the webhook's delivery log showing the 200.
The draft path
The Studio's Presentation tool loads the site in a frame and enables Next's draft mode through a route that first checks a preview secret against Sanity, so only the Studio can turn preview on. With the draft cookie set, the fetch layer switches to the drafts perspective with a read-only token, no caching, and stega on: the client encodes the source document and field path into invisible characters inside every string, and an overlay component reads them to draw click-to-edit targets.
The catch is that any string that ends up in the document head or in logic has to be fetched with stega off, or you ship zero-width characters in your meta description. Preview never touches the cache, so a draft cannot leak to a normal visitor, and a fixed banner with an exit link makes the mode visible.
The migration
A one-off script reads the old content file, uploads each image once through the assets API with a path-to-asset map, converts each body string to Portable Text with a key on every array item, and writes everything in a single transaction. Existing documents are matched by slug, label or company plus period and replaced, so the script is re-runnable without duplicates. Thirteen documents, nine images, one commit.
The script uses an editor token that lives only on my machine. The site itself only ever holds a viewer token, used for draft preview, and the webhook secret.
What broke
A Studio nested under the site's root layout inherits the site's CSS reset and looks broken; the fix is two root layouts in route groups, which the current Next version requires and which I found by reading the docs shipped in node_modules rather than trusting memory. The one-argument form of tag revalidation is deprecated and a type error now; webhooks want the explicit immediate-expiry form. The API version is a date, it has to be in the past in UTC, and tomorrow in Melbourne is still today in UTC for most of the morning.
Vercel refused the deploy because the commits were authored under a different email from the account that owns the project, which the hobby plan treats as an unauthorised contributor. Five commits re-authored and force-pushed. Its bot challenge also answered automated requests with a checkpoint page during testing, which is worth knowing because a webhook is also a non-browser request.
At a multi-site scale
Locales as first-class fields with a fallback chain, not duplicated documents per region, so thirteen regional sites share one content model and a query asks for a locale. References for shared blocks, with the webhook tagging every referencing document. Preview behind single sign-on with scoped tokens per environment.
A time-based floor under the tags, because a dropped webhook otherwise leaves a page stale forever, plus delivery monitoring and a purge-everything button. Types generated from the schema and the queries in CI, so a renamed field fails the build instead of rendering undefined. And an editorial workflow with draft, review, scheduled publish and separate edit and publish roles, because one-click publish is right for one person and wrong for a marketing team.
Stack
- Next.js
- TypeScript
- Sanity
- GROQ
- Vercel
More projects