Skip to Content
Fumadocs

Blog

Add a blog to your app.

Installation

npx @fumadocs/cli@latest add blog

It installs the components to components/blog, and the utilities of posts to lib/blog.ts.

Define a collection for your posts with blogPageSchema, and register your authors:

lib/source.ts
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',
  },
};

Write your posts under content/blog:

content/blog/hello-world.mdx
---
title: Hello World
description: My first post.
date: 2026-10-12
tags: [Announcement]
authors: [fuma]
image: /blog/hello-world.png
---
FieldDescription
datePublish date, posts are sorted by it
tagsEach tag has its page under /blog/tags
authorsKeys of your authors, unknown keys are names
imageCover image URL, shown on the cards of posts

Posts have no draft field. Keep unfinished posts outside content/blog, like in content/drafts, so they aren't published.

Pages

getPosts() resolves the authors and tags of pages, newest first. Render them in routes under your Home Layout.

Posts

src/routes/blog/index.tsx
import { createFileRoute } from '@tanstack/react-router';
import { createServerFn } from '@tanstack/react-start';
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';

const getBlogPosts = createServerFn({ method: 'GET' }).handler(() =>
  getPosts(blogSource.getPages(), blogAuthors),
);

export const Route = createFileRoute('/blog/')({
  loader: () => getBlogPosts(),
  component: Page,
});

function Page() {
  return (
    <HomeLayout {...baseOptions()}>
      <div className="mx-auto w-full max-w-(--fd-layout-width) px-4 py-12">
        <BlogCards posts={Route.useLoaderData()} />
      </div>
    </HomeLayout>
  );
}

Post

findPost() finds a post along with the newer and older posts. With toc, a floating panel shows the table of contents and a share button.

src/routes/blog/$slug.tsx
import { createFileRoute, notFound } from '@tanstack/react-router';
import { createServerFn } from '@tanstack/react-start';
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';

const getPost = createServerFn({ method: 'GET' })
  .validator((slug: string) => slug)
  .handler(({ data: slug }) => {
    const page = blogSource.getPage([slug]);
    const found = page && findPost(getPosts(blogSource.getPages(), blogAuthors), page.url);
    if (!page || !found) throw notFound();

    return { path: page.path, ...found };
  });

export const Route = createFileRoute('/blog/$slug')({
  loader: ({ params }) => getPost({ data: params.slug }),
  component: Page,
});

function Page() {
  const { path, post, newer, older } = Route.useLoaderData();
  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>
  );
}

Tags

List all tags with getTags():

src/routes/blog/tags/index.tsx
import { createFileRoute } from '@tanstack/react-router';
import { createServerFn } from '@tanstack/react-start';
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';

const getBlogTags = createServerFn({ method: 'GET' }).handler(() =>
  getTags(getPosts(blogSource.getPages())),
);

export const Route = createFileRoute('/blog/tags/')({
  loader: () => getBlogTags(),
  component: Page,
});

function Page() {
  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={Route.useLoaderData()} />
      </div>
    </HomeLayout>
  );
}

And the posts of a tag with getTagPosts(), which returns undefined for unknown tags:

src/routes/blog/tags/$tag.tsx
import { createFileRoute, notFound } from '@tanstack/react-router';
import { createServerFn } from '@tanstack/react-start';
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';

const getTag = createServerFn({ method: 'GET' })
  .validator((tag: string) => tag)
  .handler(({ data: tag }) => {
    const result = getTagPosts(getPosts(blogSource.getPages(), blogAuthors), tag);
    if (!result) throw notFound();

    return result;
  });

export const Route = createFileRoute('/blog/tags/$tag')({
  loader: ({ params }) => getTag({ data: params.tag }),
  component: Page,
});

function Page() {
  const { tag, posts } = Route.useLoaderData();

  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>{tag.name}</BlogTitle>
        </BlogHeader>
        <BlogCards posts={posts} />
      </div>
    </HomeLayout>
  );
}

Internationalization

Pass the pages of a locale to getPosts(), like blogSource.getPages(lang).

The URLs of tag pages come from getBlogUrl in lib/blog.ts. Pass it your i18n config to match the URLs of your loader:

lib/blog.ts
import { i18n } from '@/lib/i18n';

export const getBlogUrl = createGetUrl('/blog', i18n);

To publish a feed of your posts, see RSS Feed.

How is this guide?