All academies
All projects

Blog Platform

medium

Build a markdown-powered blog with tags, an author page, RSS, and static generation. You will work with typed frontmatter parsing at the file boundary, generic pagination utilities, and Next.js data functions where return types flow into page props.

Next.jsTypeScriptTailwind CSSgray-matterremark

Architecture

  • UI layer: post list, post page, tag pages, and shared PostCard and TagPill components with typed props
  • Content layer: markdown files with frontmatter, parsed and validated into a typed Post model at build time
  • Domain layer: pure utilities for sorting by date, grouping by tag, and paginating any array via a generic paginate function
  • Service layer: a posts repository module that is the only code allowed to touch the filesystem
  • Type layer: Post, PostMeta, and Paginated types shared between build-time loaders and page components

Folder structure

src/
  app/
    page.tsx
    blog/
      [slug]/
        page.tsx
    tags/
      [tag]/
        page.tsx
  components/
    PostCard.tsx
    TagPill.tsx
    Pagination.tsx
    AuthorBio.tsx
  lib/
    posts.ts
    markdown.ts
    paginate.ts
  content/
    posts/
      hello-world.md
  types/
    blog.ts

Domain type definitions

Start every project by defining its types — they become the contract for every component, service, and API call that follows.

export interface PostMeta {
  slug: string;
  title: string;
  excerpt: string;
  date: string;
  tags: string[];
  author: string;
  readingMinutes: number;
}

export interface Post extends PostMeta {
  html: string;
}

export interface Paginated<T> {
  items: T[];
  page: number;
  totalPages: number;
  totalItems: number;
}

export interface Author {
  id: string;
  name: string;
  bio: string;
  avatarUrl: string;
}

Build steps

  1. 1Define the content types — PostMeta, Post, Author, and the generic Paginated wrapper.
  2. 2Write markdown.ts to parse a raw file into frontmatter plus HTML, validating that required frontmatter fields exist and have the right types.
  3. 3Build the posts repository in posts.ts: getAllPostMeta, getPostBySlug, and getPostsByTag, all returning the shared types.
  4. 4Implement the generic paginate function and confirm its inference works for both PostMeta arrays and Author arrays.
  5. 5Build the home page listing paginated posts with PostCard and the Pagination component.
  6. 6Build the post page with generateStaticParams typed from the repository, rendering the HTML and an AuthorBio.
  7. 7Build tag pages that filter posts by tag and reuse the same list components.
  8. 8Generate an RSS feed from getAllPostMeta in a route handler with the correct content type.
  9. 9Compute readingMinutes during parsing so it is data, not something components calculate at render time.