Stage 5 track
Track: Content/CMS platform
Capstone: Publish · Builds on: Part 4, Part 8, Stage 4's QuickCart, Part 17, Part 18 · Time: ~15–20 h (one milestone every 2–3 days, ~2 hours a day)
🚧 Brief, not a built capstone. This is a short, focused plan, in the same style as the sibling Python and React courses' own Stage 5 track files — not a full Part-style lesson with its own
examples//exercises.md/solutions/. Nothing below was built, run, or verified while writing this brief. Parts 1–18's lessons (including Parts 17/18, linked throughout) were all built and verified for real against this course's harness; the Publish capstone itself was not. See "What this brief does not claim" at the bottom.
Who this track is for
You finished Stage 4's QuickCart and Parts 17–18, and the admin side of QuickCart (editing a product and having the public page catch up — the capstone's own "an admin-style edit to a product revalidates the public page that shows it" checklist item) is the thread you want to pull on: a real draft/publish workflow, where "draft" and "published" are genuinely different states with different visibility rules, not just a boolean someone forgot to flip.
Job roles this maps to: Frontend/Full-stack Engineer on a content/marketing-site or CMS-integration team — the role that builds the publishing workflow and the public-facing rendering/caching/SEO side of a site backed by editable content, whether the CMS is headless-and-bought or, like this capstone, hand-rolled.
You already have, from earlier stages:
generateMetadata,next/font, andnext/image(Part 4) — the exact tools this track's SEO work reuses, not new APIs- The component-level static/dynamic rendering spectrum (Part 8) — directly relevant to "which parts of a published page can be static, and which (a draft preview) genuinely can't"
"use cache",cacheTag/cacheLife, and on-demand revalidation viarevalidateTag/updateTag(Stage 3, Parts 10–11)- Server Actions and forms, and the public-POST-endpoint rule (Part 12)
iron-session/requireUser()(Part 15) andbetter-sqlite3with a hand-written DAL (Part 16) — this track's author-only draft editor needs both- QuickCart's own admin-edit-revalidates-public-page pattern (Stage 4 capstone) — the direct ancestor of this track's whole premise
- A real Vitest + Testing Library setup (Part 17) and local-only deployment/observability verification (Part 18)
What you'll learn, step by step
Step 1 — A draft/publish data model
Builds on: Part 16's DAL convention.
- Add a
pagestable (slug, title, body,status—"draft" | "published",published_at) and a DAL (lib/pages.ts) with separate functions for an author's view (getPageForEditing(slug)— returns any status) and the public site's view (getPublishedPage(slug)— only ever returns a row wherestatus = "published", exactly the way aWHEREclause should express this, not a check added after the query runs). - Seed at least one draft and one published page so both code paths have something real to read from day one.
Step 2 — The authoring Server Action
Builds on: Part 12 (Server Actions and forms), Part 15 (requireUser()).
- Build an author-only editor page (gated the way
checkout/admin screens already are in this course — the DAL check inside the page itself, Part 15 section 4's rule) with a form that saves a draft and a separate "Publish" action that flipsstatusto"published"and setspublished_at. - Decide, deliberately, whether saving a draft and publishing it should be one Server Action or two — and be able to justify it. (A real CMS usually keeps them separate so "save my work" never accidentally makes something public.)
Step 3 — On-demand revalidation, the capstone's own pattern extended
Builds on: Part 11 (revalidateTag/updateTag), QuickCart's admin-edit-revalidates-public-page mechanism.
- Give the public page route a
cacheTagkeyed by slug, and have the "Publish" action callrevalidateTag/updateTagfor exactly that slug the moment a page goes live — the same mechanism QuickCart's admin screen already uses for products, applied to a draft/publish state transition instead of a price/stock edit. - Verify, with a real timed before/after check (not an assumption), that a page which was previously
404(unpublished) or absent from a listing actually appears immediately after publishing, with no stale window — Part 12 section 6'supdateTag"read-your-own-writes" framing is the right one to reach for here specifically because an author publishing their own page is exactly that scenario.
Step 4 — SEO
Builds on: Part 4 (generateMetadata, next/image), Part 8 (the rendering spectrum).
- Use
generateMetadatato set a real<title>/description per published page, sourced from the page's own content — and make sure an unpublished draft's metadata is never exposed on a URL a crawler could reach (the same "don't leak draft content" discipline as the data model itself, now applied to metadata). - Decide which parts of a published page can be fully static (the body, once published and cached) versus what genuinely needs to stay dynamic (an author's live preview of an unsaved draft) — Part 8's component-level framing, not a route-level either/or.
- Add a real
sitemap.ts/robots.ts(Next.js file conventions) that lists only published pages — another place the draft/published distinction has to be enforced at the query level, not bolted on afterward.
Step 5 — Testing and deployment pass
Builds on: Part 17, Part 18, in full.
- Extend Part 17's real Vitest setup to cover
getPublishedPagedirectly (confirm a draft is genuinely never returned by this function, not just "usually" filtered by the UI) — the same "test the data-access function, not just the page that happens to call it correctly today" discipline Part 17 section 4 demonstrated. - Re-run Part 18's local verification pass against this app — in particular, re-check section 4's finding (a standalone build's SQLite file is a build-time snapshot) against this track's own
pagestable: a draft saved after buildingoutput: "standalone"would behave exactly like QuickCart Pro's cart-write finding did, landing in the traced copy, not your working database.
Step 6 — Polish (buffer)
Finish the editor UI, write the project's own README, and attempt a stretch goal.
Setup pointers (official docs only)
| Topic | Official docs |
|---|---|
generateMetadata |
the installed Metadata API reference this course already used in Part 4 |
sitemap.ts/robots.ts file conventions |
Next.js's own file-conventions reference — read the current version, don't assume the shape from memory |
Capstone brief: Publish
User stories
- As an author, I can save a draft that nobody but me (and other authors) can see.
- As an author, I can publish a draft, and the public site shows it immediately, with no stale cached 404 or stale "not found yet" state.
- As any visitor, I can never reach a draft's content or metadata through any public URL, including the sitemap.
- As a search engine (conceptually), a published page has real, page-specific metadata, not a generic site-wide title repeated everywhere.
- As a developer, I have a real, passing test proving the public read path can never return a draft, regardless of what the UI currently hides.
Architecture sketch
Author: POST /admin/pages/[slug]/publish (Server Action)
│
▼
lib/pages.ts: publishPage(slug)
│ UPDATE pages SET status='published', published_at=now WHERE slug=?
│ then revalidateTag/updateTag(`page:${slug}`)
▼
pages.sqlite (new database, same better-sqlite3 + hand-written DAL
convention as QuickCart's lib/products.ts etc.)
▲
│ getPublishedPage(slug) — WHERE status='published' always
│
Visitor: GET /[slug] (public page, cacheTag(`page:${slug}`), generateMetadata)
Milestones
- Data model —
pagestable and DAL exist;getPublishedPage/getPageForEditingare genuinely separate functions with separate guarantees. - Authoring — an author-only editor saves drafts and publishes them, gated the Part 15 way.
- Revalidation — publishing a page makes it visible on the public site immediately, verified with a real timed check.
- SEO —
generateMetadataand a sitemap both correctly include only published pages. - Tests — a real Vitest test proves
getPublishedPagecannot return a draft. - Deployment pass — Part 18's local-only checks re-run against this app, any new finding documented honestly.
Acceptance checklist
- A draft page is never reachable at its public URL, directly or via the sitemap
- Publishing a page makes it appear on the public site within the same request cycle that triggered the publish (no stale window), verified with a real timed before/after check
- Each published page's
<title>/description comes from its own content, not a shared default - A test exists that proves
getPublishedPagecannot return a draft-status row, independent of any UI behavior -
npm run lint && npm run typecheck && npm run test && npm run buildall exit0
Stretch goals
- 🟡 A scheduled-publish field (
publish_atin the future) and a check for whether this course's "works fully offline, no external cron" rule makes a real scheduler out of scope (it likely does — note the honest limit rather than faking it). - 🟡 A revision history (keep old versions of a page on each publish) — a second table, same DAL discipline.
- 🔴 Draft preview links with a signed, time-limited token so a draft can be shared with a non-author reviewer without making it genuinely public.
- 🔴
output: "standalone"'s SQLite snapshot finding (Part 18 section 4), worked all the way through for this track: design and build an explicit copy/sync step so a standalone deployment of this CMS doesn't silently diverge from its working database, and verify it for real.
How you'll know you're done
- Every item in the acceptance checklist above is ticked
- You can explain, out loud, why
getPublishedPage'sWHERE status = 'published'clause is the actual security/correctness boundary, not the editor UI that happens to hide drafts today - You can explain which parts of a published page are static versus dynamic, in Part 8's component-level terms, and why a draft preview can't be the static half
- You re-ran Part 17's and Part 18's own verification steps against this app and can point at real, current output for each
What this brief does not claim
No code for Publish — no pages DAL, no authoring Server Action, no generateMetadata/sitemap wiring — was written, run, or tested while writing this brief, unlike Parts 1–18 (including Parts 17 and 18, linked throughout this document), where every snippet was built and verified for real against this course's harness. Treat every detail above as a design-time plan until a learner (or a future content wave) actually builds it and replaces this section with real, run results.