---
order: 1
section: start
title: はじめに
description: scribe-cmsのインストールからスキーマ定義、コンテンツの作成、型安全な読み込みまでの5つのステップを解説します。
noindex: false
canonicalPath: /ja/docs/getting-started
---
## インストール

```bash
pnpm add scribe-cms zod better-sqlite3
```

動作要件として、Node 20以上、Zod v4が必要です。Scribeは特定のフレームワークに依存せず、Nodeベースの環境であればどこでも動作します。`better-sqlite3`はネイティブモジュールであるため、バンドラーの対象外に設定してください（詳細は[ランタイムAPI](/docs/runtime-api)のページを参照）。

## 1. `scribe.config.ts`の作成

プロジェクトのルートディレクトリに配置します。

```ts
import { z } from "zod";
import { defineConfig, defineContentType, field } from "scribe-cms";

const blogSchema = z.object({
  title: field.translatable(z.string().min(1)),
  description: field.translatable(z.string().min(50).max(250)),
  author: field.relation("author"),
  tags: field.structural(z.array(z.string()).default([])),
});

const authorSchema = z.object({
  name: field.structural(z.string().min(1)),
});

export default defineConfig({
  rootDir: ".", // relative to this file (CLI) / process.cwd() (runtime)
  locales: ["en", "fr", "de"],
  types: [
    defineContentType({
      id: "blog",
      path: "/blog/{slug}",
      schema: blogSchema,
      slugStrategy: "localized",
      orderBy: "-publishedAt",
    }),
    defineContentType({
      id: "author",
      contentDir: "authors",
      schema: authorSchema,
    }),
  ],
});
```

`defineConfig`と`defineContentType`は、リテラル型を保持するための恒等関数です。これにより、後で`scribe.blog`や`related(doc, "author")`を使用した際に完全な型推論が可能になります。

## 2. コンテンツの作成

```text
content/
  blog/
    hello-world.mdx
  authors/
    jane.mdx
```

```mdx
---
title: "Hello, world"
description: "A first post that says hello to the world, at length, because the schema demands fifty characters."
author: jane
publishedAt: "2026-01-15"
---

本文はMDX形式です。**Markdown**とコンポーネントの両方が使用可能です。
```

ファイル名（`hello-world`）は英語のslugとして扱われます。`publishedAt`は、すべての型で利用可能な組み込みフィールドの1つです。詳しくは[コンテンツモデル](/docs/content-model)をご覧ください。

## 3. バリデーション

`pnpm install`の実行後、`scribe` CLIコマンドがパスに追加されます。

```bash
pnpm scribe validate
pnpm scribe status
```

ビルドプロセスに組み込む場合は次のように設定します。

```json
{
  "scripts": {
    "build": "scribe validate && <お使いのフレームワークのビルドコマンド>"
  }
}
```

## 4. コンテンツの読み込み

```ts
import { createScribe } from "scribe-cms/runtime";
import config from "./scribe.config";

const scribe = createScribe(config);

const posts = scribe.blog.list(); // BlogDocの配列、新しい順
const { document } = scribe.blog.resolve("hello-world", "fr");
const author = scribe.blog.related(document!, "author"); // AuthorDoc、nullにはなりません
```

`document.frontmatter`はZodスキーマに基づいて型付けされます。詳細な仕様については[ランタイムAPI](/docs/runtime-api)を参照してください。

## 5. 翻訳

```bash
export GEMINI_API_KEY=...   # または.envファイルに記述します
npx scribe translate --locale fr
```

Scribeは、フランス語で不足しているページや古いページを検出し、`field.translatable()`で指定されたフィールドを翻訳し、その結果を`.scribe/store.sqlite`に保存します。**このディレクトリは必ずコミットしてください**。`.scribe/`を`.gitignore`に追加しないよう注意してください。詳細は[翻訳機能](/docs/translation)のページで確認できます。
