シードファイルは EmDash サイトをブートストラップする JSON ドキュメントです。コレクション、フィールド、タクソノミー、メニュー、リダイレクト、ウィジェットエリア、サイト設定、および任意のサンプルコンテンツを定義します。
ルート構造
{
"$schema": "https://emdashcms.com/seed.schema.json",
"version": "1",
"meta": {},
"settings": {},
"collections": [],
"taxonomies": [],
"bylines": [],
"menus": [],
"redirects": [],
"widgetAreas": [],
"sections": [],
"content": {}
}
| フィールド | 型 | 必須 | 説明 |
|---|---|---|---|
$schema | string | No | エディタバリデーション用の JSON スキーマ URL |
version | "1" | Yes | シードフォーマットバージョン |
meta | object | No | シードに関するメタデータ |
settings | object | No | サイト設定 |
collections | array | No | コレクション定義 |
taxonomies | array | No | タクソノミー定義 |
bylines | array | No | 署名プロフィール定義 |
menus | array | No | ナビゲーションメニュー |
redirects | array | No | リダイレクトルール |
widgetAreas | array | No | ウィジェットエリア定義 |
sections | array | No | 再利用可能なコンテンツブロック |
content | object | No | サンプルコンテンツエントリ |
Meta
シードに関する任意のメタデータ:
{
"meta": {
"name": "Blog Starter",
"description": "A simple blog with posts, pages, and categories",
"author": "EmDash"
}
}
Settings
サイト全体の設定値:
{
"settings": {
"title": "My Site",
"tagline": "A modern CMS",
"postsPerPage": 10,
"dateFormat": "MMMM d, yyyy"
}
}
設定は site: プレフィックスで options テーブルに適用されます。セットアップウィザードでユーザーは title と tagline を上書きできます。
Collections
コレクション定義でデータベースにコンテンツタイプを作成します:
{
"collections": [
{
"slug": "posts",
"label": "Posts",
"labelSingular": "Post",
"description": "Blog posts",
"icon": "file-text",
"supports": ["drafts", "revisions"],
"fields": [
{
"slug": "title",
"label": "Title",
"type": "string",
"required": true
},
{
"slug": "content",
"label": "Content",
"type": "portableText"
},
{
"slug": "featured_image",
"label": "Featured Image",
"type": "image"
}
]
}
]
}
コレクションプロパティ
| プロパティ | 型 | 必須 | 説明 |
|---|---|---|---|
slug | string | Yes | URL セーフな識別子(小文字、アンダースコア) |
label | string | Yes | 複数形の表示名 |
labelSingular | string | No | 単数形の表示名 |
description | string | No | 管理 UI の説明 |
icon | string | No | Lucide アイコン名 |
supports | array | No | 機能: "drafts", "revisions" |
fields | array | Yes | フィールド定義 |
フィールドプロパティ
| プロパティ | 型 | 必須 | 説明 |
|---|---|---|---|
slug | string | Yes | カラム名(小文字、アンダースコア) |
label | string | Yes | 表示名 |
type | string | Yes | フィールドタイプ |
required | boolean | No | バリデーション: 値が必須 |
unique | boolean | No | バリデーション: 値が一意でなければならない |
defaultValue | any | No | 新規エントリのデフォルト値 |
validation | object | No | 追加のバリデーションルール |
widget | string | No | 管理 UI ウィジェットのオーバーライド |
options | object | No | ウィジェット固有の設定 |
フィールドタイプ
| タイプ | 説明 | 保存形式 |
|---|---|---|
string | 短いテキスト | TEXT |
text | 長いテキスト(テキストエリア) | TEXT |
number | 数値 | REAL |
integer | 整数 | INTEGER |
boolean | 真偽値 | INTEGER |
date | 日付値 | TEXT (ISO 8601) |
datetime | 日付と時刻 | TEXT (ISO 8601) |
email | メールアドレス | TEXT |
url | URL | TEXT |
slug | URL セーフ文字列 | TEXT |
portableText | リッチテキストコンテンツ | JSON |
image | 画像参照 | JSON |
file | ファイル参照 | JSON |
json | 任意の JSON | JSON |
reference | 別エントリへの参照 | TEXT |
Taxonomies
コンテンツの分類システム:
{
"taxonomies": [
{
"name": "category",
"label": "Categories",
"labelSingular": "Category",
"hierarchical": true,
"collections": ["posts"],
"terms": [
{ "slug": "news", "label": "News" },
{ "slug": "tutorials", "label": "Tutorials" },
{
"slug": "advanced",
"label": "Advanced Tutorials",
"parent": "tutorials"
}
]
},
{
"name": "tag",
"label": "Tags",
"labelSingular": "Tag",
"hierarchical": false,
"collections": ["posts"]
}
]
}
タクソノミープロパティ
| プロパティ | 型 | 必須 | 説明 |
|---|---|---|---|
name | string | Yes | 一意の識別子 |
label | string | Yes | 複数形の表示名 |
labelSingular | string | No | 単数形の表示名 |
hierarchical | boolean | Yes | ネストされたターム(カテゴリ)またはフラット(タグ)を許可 |
collections | array | Yes | このタクソノミーが適用されるコレクション |
terms | array | No | 事前定義されたターム |
タームプロパティ
| プロパティ | 型 | 必須 | 説明 |
|---|---|---|---|
slug | string | Yes | URL セーフな識別子 |
label | string | Yes | 表示名 |
description | string | No | タームの説明 |
parent | string | No | 親タームのスラッグ(階層型のみ) |
Menus
管理画面から編集可能なナビゲーションメニュー:
{
"menus": [
{
"name": "primary",
"label": "Primary Navigation",
"items": [
{ "type": "custom", "label": "Home", "url": "/" },
{ "type": "page", "ref": "about" },
{ "type": "custom", "label": "Blog", "url": "/posts" },
{
"type": "custom",
"label": "External",
"url": "https://example.com",
"target": "_blank"
}
]
}
]
}
メニューアイテムタイプ
| タイプ | 説明 | 必須フィールド |
|---|---|---|
custom | カスタム URL | url |
page | ページエントリへのリンク | ref |
post | 投稿エントリへのリンク | ref |
taxonomy | タクソノミーアーカイブへのリンク | ref, collection |
collection | コレクションアーカイブへのリンク | collection |
メニューアイテムプロパティ
| プロパティ | 型 | 説明 |
|---|---|---|
type | string | アイテムタイプ(上記参照) |
label | string | 表示テキスト(page/post ref では自動生成) |
url | string | カスタム URL(custom タイプ用) |
ref | string | シード内コンテンツ ID(page/post タイプ用) |
collection | string | コレクションスラッグ |
target | string | 新しいウィンドウの場合 "_blank" |
titleAttr | string | HTML title 属性 |
cssClasses | string | カスタム CSS クラス |
children | array | ネストされたメニューアイテム |
Bylines
署名プロフィールは所有権(author_id)とは別のものです。再利用可能な署名アイデンティティを一度定義し、コンテンツエントリから参照します。
{
"bylines": [
{
"id": "editorial",
"slug": "emdash-editorial",
"displayName": "EmDash Editorial"
},
{
"id": "guest",
"slug": "guest-contributor",
"displayName": "Guest Contributor",
"isGuest": true
}
]
}
| プロパティ | 型 | 必須 | 説明 |
|---|---|---|---|
id | string | Yes | content[].bylines で使用されるシードローカル ID |
slug | string | Yes | URL セーフな署名スラッグ |
displayName | string | Yes | テンプレートと API で表示される名前 |
bio | string | No | 任意のプロフィール略歴 |
websiteUrl | string | No | 任意のウェブサイト URL |
isGuest | boolean | No | ゲストプロフィールとしてマーク |
Redirects
移行後にレガシー URL を保持するリダイレクトルール:
{
"redirects": [
{ "source": "/old-about", "destination": "/about" },
{ "source": "/legacy-feed", "destination": "/rss.xml", "type": 308 },
{
"source": "/category/news",
"destination": "/categories/news",
"groupName": "migration"
}
]
}
リダイレクトプロパティ
| プロパティ | 型 | 必須 | 説明 |
|---|---|---|---|
source | string | Yes | ソースパス(/ で始まる必要あり) |
destination | string | Yes | 宛先パス(/ で始まる必要あり) |
type | number | No | HTTP ステータス: 301, 302, 307, 308 |
enabled | boolean | No | リダイレクトが有効か(デフォルト: true) |
groupName | string | No | 管理フィルタリング/検索用の任意のグループラベル |
Widget Areas
設定可能なコンテンツ領域:
{
"widgetAreas": [
{
"name": "sidebar",
"label": "Main Sidebar",
"description": "Appears on blog posts and pages",
"widgets": [
{
"type": "component",
"title": "Recent Posts",
"componentId": "core:recent-posts",
"props": { "count": 5 }
},
{
"type": "menu",
"title": "Quick Links",
"menuName": "footer"
},
{
"type": "content",
"title": "About",
"content": [
{
"_type": "block",
"style": "normal",
"children": [{ "_type": "span", "text": "Welcome to our site!" }]
}
]
}
]
}
]
}
ウィジェットタイプ
| タイプ | 説明 | 必須フィールド |
|---|---|---|
content | リッチテキストコンテンツ | content (Portable Text) |
menu | メニューのレンダリング | menuName |
component | 登録済みコンポーネント | componentId |
組み込みコンポーネント
| コンポーネント ID | 説明 |
|---|---|
core:recent-posts | 最近の投稿リスト |
core:categories | カテゴリリスト |
core:tags | タグクラウド |
core:search | 検索フォーム |
core:archives | 月別アーカイブ |
Sections
編集者が /section スラッシュコマンドで Portable Text フィールドに挿入できる再利用可能なコンテンツブロック:
{
"sections": [
{
"slug": "hero-centered",
"title": "Centered Hero",
"description": "Full-width hero with centered heading and CTA button",
"keywords": ["hero", "banner", "header", "landing"],
"content": [
{
"_type": "block",
"style": "h1",
"children": [{ "_type": "span", "text": "Welcome to Our Site" }]
},
{
"_type": "block",
"children": [
{ "_type": "span", "text": "Your compelling tagline goes here." }
]
}
]
}
]
}
セクションプロパティ
| プロパティ | 型 | 必須 | 説明 |
|---|---|---|---|
slug | string | Yes | URL セーフな識別子 |
title | string | Yes | セクションピッカーで表示される表示名 |
description | string | No | このセクションの使用タイミングの説明 |
keywords | array | No | セクション検索用の検索語 |
content | array | Yes | Portable Text ブロック |
source | string | No | "theme"(シードのデフォルト)または "import" |
シードファイルからのセクションは source: "theme" としてマークされ、管理 UI から削除できません。編集者は独自のセクション(source: "user")を作成でき、コンテンツ編集時に任意のセクションタイプを挿入できます。
Content
コレクション別に整理されたサンプルコンテンツ:
{
"content": {
"posts": [
{
"id": "hello-world",
"slug": "hello-world",
"status": "published",
"bylines": [
{ "byline": "editorial" },
{ "byline": "guest", "roleLabel": "Guest essay" }
],
"data": {
"title": "Hello World",
"content": [
{
"_type": "block",
"style": "normal",
"children": [{ "_type": "span", "text": "Welcome!" }]
}
],
"excerpt": "Your first post."
},
"taxonomies": {
"category": ["news"],
"tag": ["welcome", "first-post"]
}
}
],
"pages": [
{
"id": "about",
"slug": "about",
"status": "published",
"data": {
"title": "About Us",
"content": [
{
"_type": "block",
"style": "normal",
"children": [{ "_type": "span", "text": "About page content." }]
}
]
}
}
]
}
}
コンテンツエントリプロパティ
| プロパティ | 型 | 必須 | 説明 |
|---|---|---|---|
id | string | Yes | 参照用のシードローカル ID |
slug | string | Yes | URL スラッグ |
status | string | No | "published" または "draft"(デフォルト: "published") |
data | object | Yes | フィールド値 |
bylines | array | No | 順序付き署名クレジット(byline、任意の roleLabel) |
taxonomies | object | No | タクソノミー名によるターム割り当て |
コンテンツ参照
$ref: プレフィックスで他のコンテンツエントリを参照:
{
"data": {
"related_posts": ["$ref:another-post", "$ref:third-post"]
}
}
$ref: プレフィックスはシード適用時にシード ID をデータベース ID に解決します。
メディア参照
URL からの画像を含める:
{
"data": {
"featured_image": {
"$media": {
"url": "https://images.unsplash.com/photo-xxx",
"alt": "Description of the image",
"filename": "hero.jpg",
"caption": "Photo by Someone"
}
}
}
}
.emdash/media/ からのローカル画像を含める:
{
"data": {
"featured_image": {
"$media": {
"file": "hero.jpg",
"alt": "Description of the image"
}
}
}
}
メディアプロパティ
| プロパティ | 型 | 必須 | 説明 |
|---|---|---|---|
url | string | Yes* | ダウンロード元のリモート URL |
file | string | Yes* | .emdash/media/ 内のローカルファイル名 |
alt | string | No | アクセシビリティ用の代替テキスト |
filename | string | No | ファイル名のオーバーライド |
caption | string | No | メディアキャプション |
*url または file のいずれかが必須で、両方は不可。
プログラムによるシードの適用
CLI ツールやスクリプト用のシード API を使用:
import { applySeed, validateSeed } from "emdash/seed";
import seedData from "./.emdash/seed.json";
// まずバリデーション
const validation = validateSeed(seedData);
if (!validation.valid) {
console.error(validation.errors);
process.exit(1);
}
// シードの適用
const result = await applySeed(db, seedData, {
includeContent: true,
onConflict: "skip",
storage: myStorage,
baseUrl: "http://localhost:4321",
});
console.log(result);
// {
// collections: { created: 2, skipped: 0 },
// fields: { created: 8, skipped: 0 },
// taxonomies: { created: 2, terms: 5 },
// bylines: { created: 2, skipped: 0 },
// menus: { created: 1, items: 4 },
// redirects: { created: 3, skipped: 0 },
// widgetAreas: { created: 1, widgets: 3 },
// settings: { applied: 3 },
// content: { created: 3, skipped: 0 },
// media: { created: 2, skipped: 0 }
// }
適用オプション
| オプション | 型 | デフォルト | 説明 |
|---|---|---|---|
includeContent | boolean | false | サンプルコンテンツエントリの作成 |
onConflict | string | "skip" | "skip", "update", "error" |
mediaBasePath | string | — | ローカルメディアファイルのベースパス |
storage | Storage | — | メディアアップロード用ストレージアダプター |
baseUrl | string | — | メディア URL のベース URL |
冪等性
シード適用は複数回実行しても安全です。エンティティタイプ別の競合動作:
| エンティティ | 動作 |
|---|---|
| コレクション | スラッグが存在する場合はスキップ |
| フィールド | コレクション + スラッグが存在する場合はスキップ |
| タクソノミー定義 | 名前が存在する場合はスキップ |
| タクソノミーターム | 名前 + スラッグが存在する場合はスキップ |
| 署名プロフィール | スラッグが存在する場合はスキップ |
| メニュー | 名前が存在する場合はスキップ |
| メニューアイテム | すべて置換(メニューが再作成される) |
| リダイレクト | ソースが存在する場合はスキップ |
| ウィジェットエリア | 名前が存在する場合はスキップ |
| ウィジェット | すべて置換(エリアが再作成される) |
| セクション | スラッグが存在する場合はスキップ |
| 設定 | 更新(設定は変更されることが前提) |
| コンテンツ | コレクション内にスラッグが存在する場合はスキップ |
バリデーション
シードファイルは適用前にバリデーションされます:
import { validateSeed } from "emdash/seed";
const { valid, errors, warnings } = validateSeed(seedData);
if (!valid) {
errors.forEach((e) => console.error(e));
}
warnings.forEach((w) => console.warn(w));
バリデーションチェック:
- 必須フィールドが存在する
- スラッグが命名規則に従っている(小文字、アンダースコア)
- フィールドタイプが有効
- 参照が既存のコンテンツを指している
- 階層的なタームの親が存在する
- リダイレクトパスが安全なローカル URL
- リダイレクトソースが一意
- コレクション内にスラッグの重複がない
CLI コマンド
# シードファイルの適用
npx emdash seed .emdash/seed.json
# サンプルコンテンツなしで適用
npx emdash seed .emdash/seed.json --no-content
# バリデーションのみ
npx emdash seed .emdash/seed.json --validate
# 現在のスキーマをシードとしてエクスポート
npx emdash export-seed > seed.json
# コンテンツ付きでエクスポート
npx emdash export-seed --with-content > seed.json