Next Static Blog

next-static-blog-site.vercel.app

Overview

A small demo I built in January 2022 to learn how Next.js builds a blog from Markdown files. Each post is a .md file in the repo. At build time, Next.js reads them and turns them into static HTML pages, so the site needs no database and no server code when people visit it.

The code is on GitHub.

Main Features

  • Home lists every post by its title
  • Post pages written in Markdown, including code
  • An About page
  • A Dark Mode switch that remembers your choice

How it works

  • One page per file: getStaticPaths lists the files in posts/, and each becomes a page.
  • Title and text: getStaticProps reads each post. gray-matter takes the title from the top of the file, and marked turns the Markdown into HTML.
  • Built once: Vercel serves the finished pages as they are, from its CDN.
  • Dark mode: the switch loads only in the browser and saves darkMode in the browser's storage.

Tech Stack

Next.js 12 · React 17 · gray-matter · marked · styled-jsx · Vercel

Architecture

Next Static Blog architecture diagram

Solid arrows are calls, and the answer comes back on the same line; dashed arrows are sent on their own.

UI Interfaces