← Writeups

Code view

How this site is built

The same pipeline as the writeup, read in the code: a schema, a loader, a renderer, a registry of islands, and a static route.

Scroll the steps on the left. The pane on the right follows, lighting the lines each step is about.

01The schema is the contract

Every writeup's frontmatter is parsed by a zod schema. The base fields are shared with blog posts; work extends them with what a project page needs: a one-line summary, a stack, links.

Defaults live here too, so the rest of the site never checks whether tags or stack exist.

src/lib/content.ts
const baseFrontmatter = z.object({  title: z.string(),  description: z.string(),  date: z.coerce.date(),  updated: z.coerce.date().optional(),  tags: z.array(z.string()).default([]),  draft: z.boolean().default(false),  cover: z.string().optional(),});export const workFrontmatter = baseFrontmatter.extend({  summary: z.string(),  role: z.string().optional(),  timeframe: z.string().optional(),  stack: z.array(z.string()).default([]),  featured: z.boolean().default(false),  links: z    .object({      live: z.url().optional(),      repo: z.url().optional(),

02A bad file fails the build

loadDoc reads a file, splits frontmatter from body with gray-matter, and runs the schema. A failure throws with the field errors, and because pages are generated at build time, the throw stops the deploy rather than shipping a broken page.

src/lib/content.ts
function loadDoc<S extends z.ZodType>(  collection: Collection,  file: string,  schema: S,): Doc<z.infer<S>> {  const slug = file.replace(/\.mdx$/, "");  const raw = fs.readFileSync(path.join(CONTENT_DIR, collection, file), "utf8");  const { data, content } = matter(raw);  const parsed = schema.safeParse(data);  if (!parsed.success) {    throw new Error(      `Invalid frontmatter in ${collection}/${file}:\n${JSON.stringify(        parsed.error.flatten().fieldErrors,        null,        2,      )}`,    );

03Drafts are a build filter

Listing a collection is just: read every file, validate, drop drafts unless this build includes them, sort newest first. includeDrafts is true in development and on Vercel previews, never in production.

src/lib/content.ts
export function getAllWork(): Doc<WorkFrontmatter>[] {  return listFiles("work")    .map((f) => loadDoc("work", f, workFrontmatter))    .filter((d) => includeDrafts || !d.frontmatter.draft)    .sort(byDateDesc);}

04One renderer for every page

MDX is compiled on the server by next-mdx-remote. GFM, heading slugs and Shiki highlighting are rehype/remark plugins; the prose ships as static HTML.

src/components/mdx/mdx.tsx
  return (    <MDXRemote      source={source}      components={{ ...mdxComponents, ...components }}      options={{        mdxOptions: {          remarkPlugins: [remarkGfm],          rehypePlugins: [            rehypeSlug,            [rehypeAutolinkHeadings, { behavior: "wrap" }],            [              rehypePrettyCode,              { theme: { dark: "github-dark", light: "github-light" } },            ],          ],        },      }}

05Islands are registered by name

A chart in a writeup is just <ColdStartBars /> in the MDX. That only works because the component is in this map; only the islands marked "use client" hydrate.

src/components/mdx/components.tsx
export const mdxComponents = {  a: Anchor,  Callout,  Figure,  Incident,  Incidents,

06The route asks for every slug up front

generateStaticParams lists every writeup, so each /work/<slug> is prerendered at build. The page itself only looks the doc up and hands it to the article layout.

src/app/work/[slug]/page.tsx
export function generateStaticParams() {  return getAllWork().map((d) => ({ slug: d.slug }));}  const { slug } = await params;  const doc = getWork(slug);  if (!doc) notFound();  const versions = getWorkVersions(slug);  return <WriteupArticle doc={doc} versions={versions} version={versions[0].version} />;