# Fumadocs (Framework Mode, Next.js): ブログ
URL: /ja/docs/next/integrations/blog
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/integrations/blog.ja.mdx

著者、タグ、記事間のナビゲーションを備えたブログを追加します。

## インストール [#installation]

```npm
npx @fumadocs/cli@latest add blog
```

`blogPageSchema` を使ってコレクションを定義し、著者を登録します。

```ts title="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',
  },
};
```

## 記事の作成 [#writing-posts]

`content/blog` 配下の各ファイルが、それぞれ1つの記事になります：

```mdx title="content/blog/hello-world.mdx"
---
title: Hello World
description: My first post.
date: 2026-10-12 # 投稿は日付の新しい順に並びます
tags: [Announcement] # タグごとに /blog/tags 以下にページが作成されます
authors: [fuma] # blogAuthors のキー。それ以外の値は名前として表示されます
image: /blog/hello-world.png # 投稿カードのカバー画像
---
```

投稿には下書き用のフィールドがないため、執筆途中の投稿は `content/blog` の外に置いてください。

<Callout title="リモート画像">
カバー画像とアバターは `next/image` でレンダリングされるため、画像のホストを
`images.remotePatterns` で許可してください。
</Callout>

## ルート [#routes]

[Home Layout](/docs/ui/layouts/home-layout) の配下にブログのルートを追加します。`getPosts()` は、ブログページを著者とタグの情報を含む投稿に変換します。投稿のフィードを作成するには、[RSS フィード](/docs/next/guides/rss)を参照してください。

### 記事一覧 [#post-list]

```tsx title="app/(home)/blog/page.tsx"
import { blogAuthors, blogSource } from '@/lib/source';
import { getPosts } from '@/lib/blog';
import { BlogCards } from '@/components/blog';

export default function Page() {
  return (
    <div className="mx-auto w-full max-w-(--fd-layout-width) px-4 py-12">
      <BlogCards posts={getPosts(blogSource.getPages(), blogAuthors)} />
    </div>
  );
}
```

### 記事ページ [#post-page]

`findPost()` は、記事とともに、その前後の記事(新しい記事と古い記事)を返します。`BlogPage` の `toc` prop を指定すると、共有ボタン付きのフローティング目次が追加されます。

```tsx title="app/(home)/blog/[slug]/page.tsx"
import { notFound } from 'next/navigation';
import { blogAuthors, blogSource } from '@/lib/source';
import { findPost, getPosts } from '@/lib/blog';
import { getMDXComponents } from '@/components/mdx';
import {
  BlogAuthors,
  BlogBackLink,
  BlogBody,
  BlogDate,
  BlogDescription,
  BlogHeader,
  BlogPage,
  BlogPostNav,
  BlogTags,
  BlogTitle,
} from '@/components/blog';

export default async function Page(props: PageProps<'/blog/[slug]'>) {
  const { slug } = await props.params;
  const page = blogSource.getPage([slug]);
  const found = page && findPost(getPosts(blogSource.getPages(), blogAuthors), page.url);
  if (!page || !found) notFound();

  const { post, newer, older } = found;
  const MDX = page.data.body;

  return (
    <BlogPage toc={page.data.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={getMDXComponents()} />
      </BlogBody>
      <BlogPostNav newer={newer} older={older} />
    </BlogPage>
  );
}
```

### タグページ [#tag-pages]

`getTags()` はすべてのタグを返します。

```tsx title="app/(home)/blog/tags/page.tsx"
import { blogSource } from '@/lib/source';
import { getPosts, getTags } from '@/lib/blog';
import { BlogHeader, BlogTagCards, BlogTitle } from '@/components/blog';

export default function Page() {
  const tags = getTags(getPosts(blogSource.getPages()));

  return (
    <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={tags} />
    </div>
  );
}
```

`getTagPosts()` は、指定したタグが付いた投稿の一覧を返します。

```tsx title="app/(home)/blog/tags/[tag]/page.tsx"
import { notFound } from 'next/navigation';
import { blogAuthors, blogSource } from '@/lib/source';
import { getPosts, getTagPosts, getTags } from '@/lib/blog';
import { BlogCards, BlogHeader, BlogTitle } from '@/components/blog';

export default async function Page(props: PageProps<'/blog/tags/[tag]'>) {
  const { tag } = await props.params;
  const result = getTagPosts(getPosts(blogSource.getPages(), blogAuthors), tag);
  if (!result) notFound();

  return (
    <div className="mx-auto flex w-full max-w-(--fd-layout-width) flex-col gap-4 px-4 py-12">
      <BlogHeader>
        <BlogTitle>{result.tag.name}</BlogTitle>
      </BlogHeader>
      <BlogCards posts={result.posts} />
    </div>
  );
}

export function generateStaticParams() {
  return getTags(getPosts(blogSource.getPages())).map((tag) => ({ tag: tag.slug }));
}
```

`output: 'export'` を指定している場合、`generateStaticParams()` が空の配列を返すと Next.js のビルドが失敗します。このルートは、タグ付きの投稿を作成してから追加してください。

## 国際化 [#internationalization]

タグの URL を生成する `getBlogUrl` に、i18n の設定を渡してください。

```ts title="lib/blog.ts"
import { i18n } from '@/lib/i18n';

// `blogSource` の `baseUrl` と常に一致させてください
export const getBlogUrl = createGetUrl('/blog', i18n);
```

ルートでは、各ロケールのページを `getPosts()` に渡します。

```ts
const posts = getPosts(blogSource.getPages(lang), blogAuthors);
```