Building Fast, SEO-Friendly Blogs with Next.js and Markdown
How I moved my blog from a database to plain Markdown files — keeping full SEO, static rendering, and VS Code-quality code highlighting.
Moving a blog from a database to Markdown files is one of those changes that pays off immediately: no connection strings, no runtime queries, and every post is a plain file you can version-control alongside your code.
Why file-based content wins
A database is overkill for content that changes a handful of times a week. With Markdown files you get:
- Zero infrastructure — no database to provision, secure, or pay for.
- Instant static rendering — pages are generated at build time.
- Great DX — write posts in your editor, review them in pull requests.
Content lives in Git, so every edit has a diff, an author, and a history.
Reading posts from disk
The core idea is simple: read the content/blog folder, parse the frontmatter,
and hand the body to a Markdown renderer.
import { readFile, readdir } from "node:fs/promises"
import matter from "gray-matter"
export async function getAllPosts() {
const files = await readdir("content/blog")
return Promise.all(
files.map(async (file) => {
const raw = await readFile(`content/blog/${file}`, "utf8")
const { data, content } = matter(raw)
return { ...data, content }
})
)
}Highlighting code the right way
Syntax highlighting happens on the server with Shiki, which uses the same grammars as VS Code. The result is accurate, themeable, and ships zero JavaScript to the browser.
yarn add rehype-pretty-code shikiThat's the whole trick — fast pages, clean HTML, and highlighting that looks like your editor.
Ready to Optimize Your Store?
Let’s discuss how we can implement these strategies for your business.