William Rafael
← Back to blog

Content architecture at scale: folders, slugs and pagination in Next.js

Organizing larger blogs and portfolios through folder conventions, stable slugs, indexing and pagination.

2023-05-08 · By willsamy · English edition

As a content collection grows, the challenge moves from rendering it to maintaining and evolving it. These patterns have worked well in Next.js.

Folder and naming conventions

  • Keep one post per file under src/content/posts/*.md.
  • Match the filename to the slug, such as supabase-next-auth.md.
  • Add collection folders only when real categories emerge, such as src/content/posts/ai/*.md.

Stable slugs

  • A slug is part of the public contract; avoid renaming it.
  • If it changes, maintain a 301 redirect map in configuration or middleware.
  • Keep dates in frontmatter rather than in slugs.

Minimal validated frontmatter

  • Include title, slug, date, description, tags, author, draft, coverImage and excerpt.
  • Validate during the build and fail early when critical data is missing.

Indexes and listings

  • Generate an index from metadata without rendering every full article.
  • Sort by descending date and hide drafts.
  • Allow tag filters without unnecessary complexity; a simple query string is often enough.

Pagination

  • Use page-based pagination, such as /blog?page=2, for predictable SEO.
  • Keep the page size stable and provide canonical links.
  • Add next and previous links with appropriate relationships.

Search and relationships

  • Client-side search over titles, descriptions and tags with a tool such as Fuse.js is enough for an MVP.
  • Relate posts through shared tags and show three to five related articles at the end.

Build and performance

  • Load metadata rather than full article bodies in listing pages.
  • Prefer slug-based routes with caching and revalidation where appropriate.

Conclusion

Simple conventions keep a growing blog manageable: filenames match slugs, frontmatter is validated, and indexes and pagination remain predictable. A stable contract makes content easier to evolve.

Content architecture at scale: folders, slugs and pagination in Next.js | William Rafael