Vineet Ganti
Sections, series and URLs
All posts

Build Logs/Building this site · Part 2 of 9

·15 min read

Sections, series and URLs

Part 2 of the build log for this site. How a flat list of posts became shelves and reading orders: three labels in frontmatter, one config file, two prerendered routes, readable slugs with permanent redirects, and an image folder per post.

Next.jsInformation architectureRedirectsMDX

By late October the blog was one list sorted by date: an essay about writing sat between two posts on transformer inference, and the only clue that six posts formed a series was a hand-written list at the top of each. This part is about the structure that replaced it, and the clean-up of names, URLs and images that came with it.

#TL;DR

  • A post carries three labels: a section (the shelf), an optional series with a part number (the reading order), and free-form tags.
  • All sections and series are defined in one file, src/lib/sections.ts. The routes, chips and cards read from it, so a new shelf is one entry.
  • parsePost reads the labels with fallbacks: an unknown section lands in Essays, and a missing part number is undefined, never NaN.
  • Two routes, /blog/topic/[section] and /blog/series/[series], are two segments deep, so they can never collide with a post's slug, and every one is prerendered.
  • Renamed posts answer 308 Permanent Redirect to their new address. The old build-log post, split into this series, now redirects to the series page.

#Why one list stopped working

Once there were a dozen posts, the flat list had three problems:

  • No way to browse by topic. Every post, essay or deep dive, sat in one stream.
  • No reading order. A series was implied by titles, not by the site.
  • Overlapping tags. "AI", "LLMs" and "AI Engineering" mean nearly the same thing, so they made poor shelves.

#Three labels, three jobs

LabelQuestion it answersHow many per postIn frontmatter
SectionWhich shelf is this on?Exactly one, from a short fixed listsection: "build-logs"
SeriesIn what order should I read it?Zero or oneseries: "building-this-site" and seriesOrder: 2
TagWhat is it about, in detail?Any numbertags: ["Next.js", "MDX"]

One label couldn't do all three jobs: a shelf has to be small and stable, an order has to be explicit, and detail has to be free. This post's own frontmatter shows all three:

yamlcontent/blog/site-sections-and-series.mdx (frontmatter)
---
title: "Sections, series and URLs"
date: "2026-11-13"
section: "build-logs"
series: "building-this-site"
seriesOrder: 2
tags: ["Next.js", "Information architecture", "Redirects", "MDX"]
---

#One config file for every shelf

Sections and series live in one list in src/lib/sections.ts:

tssrc/lib/sections.ts (shortened)
export const SECTIONS: Section[] = [
  { slug: "ai-llms", title: "AI & LLMs", description: "..." },
  { slug: "systems", title: "Systems & Engineering", description: "..." },
  { slug: "data-engineering", title: "Data Engineering", description: "..." },
  { slug: "build-logs", title: "Build Logs", description: "..." },
  { slug: "essays", title: "Essays & Ideas", description: "..." },
];

/** Where a post lands when its `section` is missing or misspelled. */
export const DEFAULT_SECTION = "essays";

export const SERIES: Series[] = [
  { slug: "llm-architectures", title: "LLM Architectures", description: "..." },
  // agentic-ai, database-engineering, de-sql, building-this-site, mit-distributed-systems
];

The rule for growing it is written into the project's notes: add a section only when three or more posts need it, and until then file a post under Essays with a tag. A series that isn't listed still works, because getSeriesInfo builds a title from its slug ("building-this-site" becomes "Building This Site"); listing it only adds a proper title and a description for the series page.

#Reading the labels: parsePost

blog.ts turns a file into a BlogPost in one place, so a new field is added once:

tssrc/lib/blog.ts
function parsePost(slug: string, fileContent: string): BlogPost {
  const { data, content } = matter(fileContent);
  const stats = readingTime(content);
  const order = Number(data.seriesOrder);

  return {
    slug,
    title: data.title || slug,
    description: data.description || "",
    date: data.date || new Date().toISOString(),
    tags: data.tags || [],
    section: getSection(data.section) ? data.section : DEFAULT_SECTION,
    series: data.series || undefined,
    seriesOrder: Number.isFinite(order) ? order : undefined,
    readingTime: stats.text,
    listenMinutes: estimateListenMinutes(content),
    audioSrc: findAudio(slug, data.audio),
    toc: data.toc !== false,
    content,
  };
}

Three of those lines are defensive on purpose:

  • An unknown section falls back to essays, so a typo moves a post to another shelf instead of breaking the build.
  • Number.isFinite(order) turns a missing seriesOrder into undefined. Without it, Number(undefined) is NaN, and NaN makes any sort that uses it unpredictable.
  • A missing title or date has a default. That one is a mixed blessing: a file with no frontmatter at all still parses, so nothing flags it. 📜 On 2026-11-13 a pasted notes file without frontmatter reached Vercel and failed the prerender. My first diagnosis blamed the missing date, but parsePost had defaulted it to "now"; the real cause was Rust code outside a code fence, where MDX read fn main() { as the start of a JavaScript expression. The file was moved out of content/blog/, and a second pasted file was fixed by putting its <command> placeholders in backticks.

On top of parsePost sit small queries, each a filter over getAllPosts():

tssrc/lib/blog.ts
export function getPostsBySeries(series: string): BlogPost[] {
  return getAllPosts()
    .filter((p) => p.series === series)
    .sort((a, b) => (a.seriesOrder ?? 0) - (b.seriesOrder ?? 0));
}

export function getSeriesPosition(post: BlogPost): SeriesPosition | null {
  if (!post.series) return null;
  const posts = getPostsBySeries(post.series);
  const i = posts.findIndex((p) => p.slug === post.slug);
  if (i === -1) return null;
  return { position: i + 1, total: posts.length, prev: posts[i - 1], next: posts[i + 1] };
}

A series is ordered by seriesOrder, not by date. All nine parts of this series share one date, and a date can change; an explicit order can't be confused by either.

📘 These queries all call getAllPosts(). It used to read and parse every file on every call, on the theory that at about 50 posts a build is cheap enough without a cache. 📜 That theory failed on 2026-11-17: a one-worker Vercel build re-parsed every post a dozen times per list page and timed out after 60 seconds. getAllPosts() now keeps its result until a post file changes on disk (it compares each file's modification time and size), and the build of 54 posts runs in about 10 seconds.

#Two routes, kept apart by depth

RouteFileWhat it shows
/blog/topic/[section]src/app/blog/topic/[section]/page.tsxOne shelf: its series and its posts
/blog/series/[series]src/app/blog/series/[series]/page.tsxOne series, in reading order

Both follow the same pattern as the post page:

tsxsrc/app/blog/series/[series]/page.tsx (shortened)
export function generateStaticParams() {
  return getSeriesSlugs().map((series) => ({ series })); // every series that has a post
}

export default async function BlogSeriesPage({ params }: { params: Promise<{ series: string }> }) {
  const { series: slug } = await params; // in this Next.js, params is a Promise
  const posts = getPostsBySeries(slug);
  if (posts.length === 0) notFound(); // an unknown series is a 404
  // ...the title, the description and the posts in order
}

Why real routes and not a ?section= filter on /blog? A route gives every shelf and reading list its own address that can be shared, bookmarked and indexed, and it lets each one be built as static HTML. A query string would make /blog depend on the request, and it couldn't be prerendered per filter.

#The interface

The blog page: a row of section chips with counts, then series cards, then the latest posts, each labelled with its section and part number

ComponentJob
SectionNavThe chip row with counts. A section with no posts is hidden, and the active chip carries aria-current="page" for screen readers
SeriesStripA card for each series with its post count
SeriesNavPrevious and next links at the end of a series post
PostCardShows the section and "Series · Part N"
Post headerThe section and "Part N of M" as links above the title

The top of a post in this series: Build Logs / Building this site · Part 2 of 9 above the date, the title, the tags and the Listen to this post button

The series list at the top of each post is generated too. Hand-written lists drift: a new post is added to one and forgotten in the others. The two newest series have a small script each, scripts/db-lab/series-callouts.mjs and scripts/build-log/series-callouts.mjs, that rewrites the list between two marker comments in every post, with the current one in bold. The markers are MDX comments, {/* series:start */} and {/* series:end */}, so they render as nothing.

#Renames and redirects

With shelves in place, the old names stopped making sense. The six LLM posts were mentiforce01 to mentiforce06, the name of the person the series credits, not a description. They got readable slugs, and their titles lost the "LLM Architectures - 0N -" prefix that the section and the part label now show.

Changing a published URL breaks every link to it, so redirects() in next.config.ts sends the old addresses on:

tsnext.config.ts (shortened)
const RENAMED_POSTS: Record<string, string> = {
  mentiforce01: "python-internals-for-llms",
  // ...mentiforce02 to 06, and the old MapReduce file name with its spaces
};

async redirects() {
  return [
    ...Object.entries(RENAMED_POSTS).map(([from, to]) => ({
      source: `/blog/${from}`,
      destination: `/blog/${to}`,
      permanent: true, // 308
    })),
    // The single build-log post became this series.
    { source: "/blog/how-this-site-is-built", destination: "/blog/series/building-this-site", permanent: true },
    // The old Good reads page lives inside the Memex page now. Temporary while that page is a beta.
    { source: "/reads", destination: "/memex#good-reads", permanent: false },
    // The Memex page was called Second brain until 2026-11-18. Permanent, so feed readers move the subscription.
    { source: "/second-brain", destination: "/memex", permanent: true },
    { source: "/second-brain/feed.xml", destination: "/memex/feed.xml", permanent: true },
  ];
},

Permanent or temporary is a real decision. permanent: true sends 308 Permanent Redirect: browsers and search engines remember it and stop asking for the old address. That is right for a rename that will never be undone. /reads uses permanent: false, a 307 Temporary Redirect, because the page it points at is a beta. If the beta is withdrawn, a remembered 308 would keep sending people to a page that no longer exists.

✅ Checked on a production server on 2026-11-18 (first on 2026-11-13, re-run after the Memex rename):

bashCommand
for p in mentiforce01 how-this-site-is-built; do curl -s -o /dev/null -w "%{http_code} %{redirect_url}\n" http://localhost:3000/blog/$p; done
for p in reads second-brain second-brain/feed.xml; do curl -s -o /dev/null -w "%{http_code} %{redirect_url}\n" http://localhost:3000/$p; done
textOutput
308 http://localhost:3000/blog/python-internals-for-llms
308 http://localhost:3000/blog/series/building-this-site
307 http://localhost:3000/memex#good-reads
308 http://localhost:3000/memex
308 http://localhost:3000/memex/feed.xml

#Images: a folder per post

Images used to sit in loose folders such as public/llm-vllm-engine/. They now mirror the blog's structure:

textWhere images live
public/images/<section>/<series>/<post-slug>/diagram.svg
public/images/build-logs/building-this-site/site-architecture/two-paths.svg
public/images/essays/ideal-chat-app/message_send_flow.png        (no series, so straight under the section)

They sit under images/ and not blog/ on purpose: a folder named public/blog/ would share the /blog/... URL space with the pages, and a file there could shadow a route.

#Things that can trip you up

  • A typo in section doesn't fail. It quietly files the post under Essays. Check the post's shelf after adding it.
  • Two posts with the same seriesOrder. The sort keeps them, in an order you didn't choose. Number the parts 1 to n with no gaps.
  • A permanent redirect is hard to take back. Browsers cache a 308. Use 307 for anything that might change.
  • Raw notes in content/blog/. Every file there is compiled as MDX, so pasted code outside a fence, or a bare < or { in prose, fails the build. Keep raw notes in the git-ignored raw/ folder.
  • Forgetting the sibling posts. A new part of a series needs the series list updated in every part; run the series script rather than editing lists by hand.

#Reproduce this yourself

  1. ✅ See the routes. Run npm run build and read the route table: every /blog/topic/... and /blog/series/... page is listed as prerendered.
  2. ✅ Check the redirects. npx next start, then the curl commands above. A 308 or 307 and the new address mean the redirect works.
  3. ✅ Add a series part. Give the post series and seriesOrder, add it to the list in scripts/build-log/series-callouts.mjs, run node scripts/build-log/series-callouts.mjs, and check the list in each part.
  4. 📘 Add a shelf. One entry in SECTIONS in src/lib/sections.ts. The chips, the section page and the post labels pick it up with no other change.

#Summary

Every post now has a shelf, an optional place in a reading order, and free-form tags, all set in frontmatter and read by one parser that falls back instead of failing. One config file defines the shelves and series; two routes, two segments deep, give each one a prerendered page; and every renamed URL redirects, permanently for renames and temporarily for anything that might be withdrawn. Images live in a folder per post that mirrors the blog.

#Key takeaways

  • Separate "where it lives", "what order" and "what about": they are three different labels.
  • Keep the list of shelves in one place, and make everything else read from it.
  • Give every shelf and reading list a real, prerendered URL.
  • Never break a URL: redirect it, and choose permanent or temporary on purpose.

#Concepts at a glance

TermIn one line
SectionThe one shelf a post sits on
SeriesAn ordered reading list, ordered by seriesOrder
FallbackA safe default for a bad value, so the build keeps going
Dynamic segmentA [name] folder in the App Router, filled from the URL
308 Permanent RedirectRemembered by browsers and search engines; for renames
307 Temporary RedirectNot remembered; for anything that may change
Series callout scriptRewrites the series list in every part between marker comments

#Test yourself

Why are series ordered by seriesOrder and not by date?

Several parts can share a date, and a date can be corrected later. An explicit number is stable and says exactly what the author meant.

Why can't a post called "topic" hide the /blog/topic/... pages?

A post's URL is one segment after /blog, while the section pages are two segments deep. /blog/topic and /blog/topic/build-logs are different routes.

Why is /reads a 307 when the renamed posts are 308s?

The renames are final, so browsers may remember them. /reads points at a beta page that might be withdrawn, and a remembered permanent redirect would keep sending people to a page that is gone.

What happens to a post with section: "buildlogs" (a typo)?

parsePost doesn't find that section, so the post falls back to Essays & Ideas. The build passes, which is why the shelf is worth checking after adding a post.

#Sources