How this site is built
One Next.js server in a Docker container, MDX files on disk edited from a small admin, Shiki on the server, and ads kept in their own boxes. No database.
- published
- updated
- reading time
- 3 min
This site is a single Next.js server running in a Docker container behind a reverse proxy. Every page is rendered on the server from files on disk. There is no database: the content is the filesystem.
It started as a static export on a CDN. That stopped working once I wanted to edit posts from a browser, because every edit needed a rebuild and a redeploy. Moving to one small server traded "nothing to patch" for "edits are live the moment I save".
Requirements
The constraints I set before writing any code:
- Content lives as MDX and JSON files, readable and diffable without the app.
- Edits from the admin show up immediately and survive container rebuilds.
- Pages work with JavaScript disabled. JavaScript only adds navigation prefetch and ad slots.
- Ads never appear on the homepage or case studies, and never appear before the reader has some text.
Content pipeline
Posts are plain files in content/blog. Frontmatter is parsed with gray-matter, and the body is compiled by next-mdx-remote inside a React Server Component, so none of the MDX tooling ships to the browser.
const { content } = await compileMDX({
source,
components: mdxComponents,
options: {
mdxOptions: {
remarkPlugins: [remarkGfm],
rehypePlugins: [rehypeSlug, [rehypePrettyCode, prettyCode]],
},
},
})Syntax highlighting runs through Shiki on the server. The output is plain <span> elements with inline colours, so there is no highlighter runtime and no layout shift.
Rendering per request
Pages are rendered at request time rather than at build time, so a file changed on disk is visible on the next page load. Compiling MDX and running Shiki on every request would be wasteful, so compiled output is cached in memory, keyed by the source text:
export function renderMDX(source: string): Promise<ReactElement> {
const hit = cache.get(source)
if (hit) return hit
const pending = compile(source)
pending.catch(() => cache.delete(source))
if (cache.size >= MAX_ENTRIES) cache.delete(cache.keys().next().value!)
cache.set(source, pending)
return pending
}Editing a post changes its source, which changes the key. There is nothing to invalidate.
Reading time
Reading time is word count divided by 225, with fenced code excluded. People skim code instead of reading it at prose speed.
Tag filtering
Tag filters are routes, not client state. /blog/tags/[tag] filters the post list on the server and returns a 404 for tags no post uses. Each filter has its own URL, can be indexed, and needs no JavaScript.
Admin
/admin edits blog posts, case studies, the about/privacy/terms pages and the JSON data behind the homepage. It writes straight back to the files in content/. Login is a single password from the environment, with a signed session cookie and a per-IP lockout after repeated failures. With no password set in production, login is disabled rather than falling back to a default.
Ad isolation
Ad units go through one component, AdBanner. It labels the slot, reserves height before the ad loads, and renders nothing when the provider isn't configured.
On article pages, one in-article unit sits after the second paragraph, and one more after the post. The in-article unit is inserted by a small rehype plugin during MDX compilation, so posts never contain ad markup and short posts (fewer than four paragraphs) skip it. On wide screens there is also a unit below the table of contents.
note
The homepage and case studies never import AdBanner. That rule is enforced by convention and noted at the top of each file.
Deploying
docker compose up -d --buildThe image is built from Next's standalone output and runs as an unprivileged user. content/ is bind-mounted from the host, so rebuilding the image never touches posts, and admin edits can be committed from the server to keep a history. The container listens on localhost only; Caddy in front handles HTTPS and redirects the .id domain to .com.