Content
content, from sanoma/site, is the Markdown under the company repo’s content/, as of the build: each folder directly under content/ is a kind, and each *.md directly in it an entry, its slug the file’s name. Both names are URL segments (/^[a-z][a-z0-9-]*$/); subfolders, .mdx and other files are left alone. A post, content/posts/zapier-and-sanoma.md, and the page that shows it:
---title: Zapier and Sanomadescription: How they differ.publishedAt: 2026-10-01---
What a visitor reads, in **Markdown** (GFM: tables, task lists, strikethrough).// sites/www/routes/blog.$slug.tsximport { createFileRoute } from "@tanstack/react-router";import { content, notFound } from "sanoma/site";import { NotFound } from "../components/not-found.tsx";
export const Route = createFileRoute("/sites/www/blog/$slug")({ loader: async ({ params }) => { const post = await content.posts.get(params.slug); if (!post) throw notFound(); return post; }, // Not found, it gives no title: the app's "Page not found" stays. head: ({ loaderData }) => ({ meta: loaderData ? [{ title: loaderData.data.title }] : [] }), component: Post, // Drawn here, inside the site's layout. notFoundComponent: NotFound,});
function Post() { const post = Route.useLoaderData(); return <article className="prose" dangerouslySetInnerHTML={{ __html: post.html }} />;}| Call | What it gives |
|---|---|
content.posts.list() |
Every file of content/posts/, sorted by slug, as { slug, data }: data is the front matter ({} with none) |
content.posts.get(slug) |
One file, { slug, data, body, html }: body the Markdown after the front matter as written, html it rendered at build; undefined when there is no such file |
content.<kind> with no folder |
list() gives [] and get() undefined; once .sanoma/content.ts types content, it does not type-check |
-
Translations:
content/posts/hello.fr.mdishelloin French, besidehello.md, the site’s default language’s. Its front matter is laid over the original’s, so what it does not repeat (a date, an image,draft) is the original’s: a draft’s translation is a draft unless it saysdraft: false. A translation with front matter alone keeps the original’s body.list({ locale })andget(slug, { locale })give each slug’s file in that language, else its<slug>.md(an entry’slocalesays which: absent for<slug>.md); withoutlocale,<slug>.mdalone, as before translations. A language is a tag such asfrorpt-BR(Languages). -
Not found: a loader’s
notFound()is drawn by the nearest route, from the page up, with anotFoundComponent, in place of that route: give the page one, as above, and the site’s layout one too (sites/www/routes/route.tsx), which draws a path no page has inside the layout. A page whose route has none draws in the layout’s place when the layout has one, and, with neither, the app’s not-found notice takes the page’s place (on a public site’s own host, a plain page). Its head runs with noloaderData. -
Front matter is YAML between a first line
---and the next---line, read as YAML 1.2, so an unquoted date stays a string. A file whose front matter is not a mapping is left out, andsanoma checkreports it at its line. -
HTML is rendered at build with
marked(GFM), so no Markdown library ships to the browser. Raw HTML in a file passes through: content is reviewed as code is. The kit has no styles for it; give thearticleyour own classes. -
Drafts: an entry whose front matter has
draft: trueis there whilesanomaserves the sites from its dev server, and never in a build: not on a page, not in any file sent to the browser. -
Loading: the content is one chunk of the browser’s bundle, loaded on the first call, and part of the server’s render, so a loader’s
await content.posts.list()adds no request. A change undercontent/is a new build (the build’s key covers it). On the dev server, a file saved undercontent/shows on the next render of an open page, with no restart. -
Types:
.sanoma/content.ts, written with the sites’ generated files (and again on the dev server when a file undercontent/changes), typescontentby augmentingRegister, as.sanoma/api.tstypesapi: each kind’sdatais the union of its files’ front matter, drafts included, a key in every file required and?otherwise; strings, numbers, booleans andnullas themselves, a list as an array of its items’ types, a mapping as an object merged the same way (so rows of a table in the front matter share one type). Values are never types:status: draftis astring. Until it is written,contentis untyped.
readContent(repo, { drafts }) and contentTypes(kinds), from sanoma/app/build, are what the build and sanoma check read with: the kinds and the problems, each { file, line, column, message }, and the text of .sanoma/content.ts (CONTENT_TYPES).
These pages describe sanoma 0.11.24.