Blog
Add a blog with authors, tags and post navigation.
Installation
npx @fumadocs/cli@latest add blogDefine a collection with blogPageSchema, and register your authors:
import { defineCollections } from 'fumadocs-mdx/macro';
import { loader } from 'fumadocs-core/source';
import { type BlogAuthor, blogPageSchema } from './blog';
export const blog = defineCollections({
type: 'doc',
dir: 'content/blog',
schema: blogPageSchema,
});
export const blogSource = loader({
baseUrl: '/blog',
source: blog.toFumadocsSource(),
});
export const blogAuthors: Record<string, BlogAuthor> = {
fuma: {
name: 'Fuma Nama',
title: 'Maintainer',
url: 'https://fuma-nama.dev',
image: 'https://avatars.githubusercontent.com/u/76240755',
},
};Writing Posts
Each file under content/blog is a post:
---
title: Hello World
description: My first post.
date: 2026-10-12 # posts are sorted by date, newest first
tags: [Announcement] # each tag has a page under /blog/tags
authors: [fuma] # keys of blogAuthors, other values show as names
image: /blog/hello-world.png # cover image on the post card
---Posts have no draft field, so keep unfinished posts outside content/blog.
Routes
Add the blog routes under your Home Layout. getPosts() turns blog pages into posts with their authors and tags. For a feed of your posts, see RSS Feed.
Post List
import type { Route } from './+types/blog';
import { HomeLayout } from 'fumadocs-ui/layouts/home';
import { baseOptions } from '@/lib/layout.shared';
import { blogAuthors, blogSource } from '@/lib/source';
import { getPosts } from '@/lib/blog';
import { BlogCards } from '@/components/blog';
export function loader() {
return getPosts(blogSource.getPages(), blogAuthors);
}
export default function Page({ loaderData }: Route.ComponentProps) {
return (
<HomeLayout {...baseOptions()}>
<div className="mx-auto w-full max-w-(--fd-layout-width) px-4 py-12">
<BlogCards posts={loaderData} />
</div>
</HomeLayout>
);
}Post Page
findPost() returns a post with its newer and older posts. The toc prop of BlogPage adds a floating table of contents with a share button.
import type { Route } from './+types/blog.post';
import { HomeLayout } from 'fumadocs-ui/layouts/home';
import { baseOptions } from '@/lib/layout.shared';
import { blog, blogAuthors, blogSource } from '@/lib/source';
import { findPost, getPosts } from '@/lib/blog';
import { useMDXComponents } from '@/components/mdx';
import {
BlogAuthors,
BlogBackLink,
BlogBody,
BlogDate,
BlogDescription,
BlogHeader,
BlogPage,
BlogPostNav,
BlogTags,
BlogTitle,
} from '@/components/blog';
export function loader({ params }: Route.LoaderArgs) {
const page = blogSource.getPage([params.slug]);
const found = page && findPost(getPosts(blogSource.getPages(), blogAuthors), page.url);
if (!page || !found) throw new Response('Not Found', { status: 404 });
return { path: page.path, ...found };
}
export default function Page({ loaderData }: Route.ComponentProps) {
const { path, post, newer, older } = loaderData;
const page = blog.get(path)!;
const MDX = page.body;
return (
<HomeLayout {...baseOptions()}>
<BlogPage toc={page.toc}>
<BlogHeader>
<BlogBackLink href="/blog" />
<BlogTitle>{post.title}</BlogTitle>
<BlogDescription>{post.description}</BlogDescription>
<BlogAuthors authors={post.authors} />
<BlogTags tags={post.tags} />
{post.date && <BlogDate date={post.date} />}
</BlogHeader>
<BlogBody>
<MDX components={useMDXComponents()} />
</BlogBody>
<BlogPostNav newer={newer} older={older} />
</BlogPage>
</HomeLayout>
);
}Tag Pages
getTags() lists every tag:
import type { Route } from './+types/blog.tags';
import { HomeLayout } from 'fumadocs-ui/layouts/home';
import { baseOptions } from '@/lib/layout.shared';
import { blogSource } from '@/lib/source';
import { getPosts, getTags } from '@/lib/blog';
import { BlogHeader, BlogTagCards, BlogTitle } from '@/components/blog';
export function loader() {
return getTags(getPosts(blogSource.getPages()));
}
export default function Page({ loaderData }: Route.ComponentProps) {
return (
<HomeLayout {...baseOptions()}>
<div className="mx-auto flex w-full max-w-(--fd-layout-width) flex-col gap-4 px-4 py-12">
<BlogHeader>
<BlogTitle>All Tags</BlogTitle>
</BlogHeader>
<BlogTagCards tags={loaderData} />
</div>
</HomeLayout>
);
}getTagPosts() lists the posts of a tag:
import type { Route } from './+types/blog.tag';
import { HomeLayout } from 'fumadocs-ui/layouts/home';
import { baseOptions } from '@/lib/layout.shared';
import { blogAuthors, blogSource } from '@/lib/source';
import { getPosts, getTagPosts } from '@/lib/blog';
import { BlogCards, BlogHeader, BlogTitle } from '@/components/blog';
export function loader({ params }: Route.LoaderArgs) {
const result = getTagPosts(getPosts(blogSource.getPages(), blogAuthors), params.tag);
if (!result) throw new Response('Not Found', { status: 404 });
return result;
}
export default function Page({ loaderData }: Route.ComponentProps) {
return (
<HomeLayout {...baseOptions()}>
<div className="mx-auto flex w-full max-w-(--fd-layout-width) flex-col gap-4 px-4 py-12">
<BlogHeader>
<BlogTitle>{loaderData.tag.name}</BlogTitle>
</BlogHeader>
<BlogCards posts={loaderData.posts} />
</div>
</HomeLayout>
);
}Internationalization
Pass your i18n config to getBlogUrl, which creates the URLs of tags:
import { i18n } from '@/lib/i18n';
// keep in sync with the `baseUrl` of `blogSource`
export const getBlogUrl = createGetUrl('/blog', i18n);In routes, pass the pages of a locale to getPosts():
const posts = getPosts(blogSource.getPages(lang), blogAuthors);How is this guide?
Last updated on
