Next.js starter¶
A multilingual blog on Next.js 16 (App Router) and GoHead: articles, authors and
categories with drafts, English and French, a home page edited in GoHead, Markdown bodies,
Open Graph metadata, a sitemap and RSS feeds, light and dark themes, and pages that refresh
when you publish. Its source is in
templates/nextjs-blog.
To see every GoHead feature at work (forms, previews, GraphQL, agents), use the conference
starter of the feature tour instead.
Create it¶
You need Node.js 20.9+ and, to run GoHead locally, Docker.
npm create @gohead-cms@latest my-blog # pnpm create @gohead-cms, yarn create @gohead-cms…
cd my-blog
docker compose up -d # GoHead on :8080, its admin UI on :3001
npm run gohead:setup # content model, sample articles, types
npm run dev # http://localhost:3000
npm create copies the template, installs its dependencies and writes .env.local
(--template, --url <your GoHead>, --no-install, --yes). The template's
docker-compose.yml runs GoHead with an admin / gohead-local-password account bound
to localhost; with a GoHead you already run, set GOHEAD_URL, GOHEAD_USERNAME and
GOHEAD_PASSWORD in .env.local instead.
| Script | |
|---|---|
gohead:push |
Applies gohead/model.json: locales, the seo component, collections, singletons, public access (models as code) |
gohead:seed |
Uploads gohead/media/ and creates the entries of gohead/seed.json |
gohead:types |
Writes src/gohead.d.ts from the model |
gohead:setup |
The three, in order |
dev, build, start, lint, typecheck |
The usual |
How it is built¶
| GoHead | Site |
|---|---|
site singleton |
Header, footer and default metadata of every page |
homepage singleton |
Hero and featured articles of /en and /fr |
articles (draft and publish) |
The article list (?page=) and /[locale]/articles/[slug] |
categories, authors |
Navigation, bylines, /[locale]/categories/[slug], /[locale]/authors/[slug] |
- Reads live in
src/lib/gohead.ts: one server-only client from@gohead-cms/client, typed bysrc/gohead.d.ts. The site reads published content through public access, opened by the model'spublickey, so it needs no token; setGOHEAD_TOKENfor a private GoHead. - Languages:
/redirects to/enor/frfrom the browser's language; localized attributes fall back to English; slugs are shared, so the language switcher keeps the page. - Bodies are Markdown, rendered without raw HTML.
Publishing and revalidation¶
Pages are static. Every GoHead read is cached with the tags gohead and
gohead:<collection> (gohead:singleton:<name> for singletons) and refetched after
GOHEAD_REVALIDATE seconds (60). With a webhook, changes show up on the next visit:
- In GoHead, Settings → Webhooks: URL
https://your-site/api/revalidate, all events. - Put the signing secret GoHead shows (
whsec_…) inGOHEAD_WEBHOOK_SECRET.
src/app/api/revalidate/route.ts checks the signature with parseWebhook and expires the
tags of the collection or singleton the event is about. GoHead refuses webhook URLs on
private addresses unless webhooks.allow_private_networks is on: the template's
docker-compose.yml turns it on for local work, so a webhook can target
http://host.docker.internal:3000/api/revalidate.
Make it yours¶
- Change
gohead/model.json(the$schemagives your editor completion), thennpm run gohead:pushandnpm run gohead:types. - Fix what TypeScript reports, and build pages with the typed client.
- Deploy anywhere Next.js runs (Vercel, a Node server, a container) with
GOHEAD_URL,GOHEAD_WEBHOOK_SECRETandNEXT_PUBLIC_SITE_URL, and point the webhook at it.
A build that can't reach GoHead still succeeds and renders pages on their first visit.