コンテンツにスキップ

EmDash 入門

このガイドでは、インストールから最初の投稿を公開するまで、初めてのEmDashサイトを作成する手順を説明します。

EmDashが適切なAstro CMSかどうかまだ検討中の場合は、まずEmDashとは?または最適なAstro CMSをお読みいただき、その後このセットアップガイドに戻ってください。

  • Node.js v22.12.0 以上(奇数バージョンはサポートされていません)
  • npm、pnpm、または yarn
  • コードエディタ(VS Code推奨)
Terminal window
npm create emdash@latest

プロンプトに従ってプロジェクト名を付け、設定を行ってください。

  1. プロジェクトディレクトリに移動します:

    Terminal window
    cd my-emdash-site
  2. 依存関係をインストールします:

    Terminal window
    npm install
  3. 開発サーバーを起動します:

    Terminal window
    npm run dev
  4. ブラウザで `http://localhost:4321“ を開きます

セットアップウィザードの完了

Section titled “セットアップウィザードの完了”

管理パネルに初めてアクセスすると、EmDashのセットアップウィザードが初期設定を案内します:

  1. `http://localhost:4321/_emdash/admin“ に移動します

  2. セットアップウィザードにリダイレクトされます。以下を入力してください:

    • サイトタイトル — サイトの名前
    • タグライン — 短い説明
    • 管理者メールアドレス — あなたのメールアドレス
  3. サイト作成をクリックしてパスキーを登録します

  4. ブラウザがTouch ID、Face ID、Windows Hello、またはセキュリティキーを使用したパスキーの作成を促します

パスキーが登録されると、ログイン状態になり管理ダッシュボードにリダイレクトされます。

EmDash admin dashboard showing content overview, recent activity, and navigation sidebar
  1. 管理サイドバーで、コンテンツの下の投稿をクリックします。

  2. 新規投稿をクリックします。

  3. タイトルを入力し、リッチテキストエディターを使用してコンテンツを記述します。

    EmDash post editor with rich text toolbar and publish sidebar
  4. ステータスを公開に設定し、保存をクリックします。

  5. サイトのホームページにアクセスして、投稿がライブで表示されていることを確認します—再ビルドは不要です!

EmDashプロジェクトは、いくつかの追加要素を含む標準的なAstro構造に従います:

my-emdash-site/
├── astro.config.mjs # Astro + EmDash configuration
├── src/
│ ├── live.config.ts # Live Collections configuration
│ ├── pages/
│ │ ├── index.astro # Homepage
│ │ └── posts/
│ │ └── [...slug].astro # Dynamic post pages
│ ├── layouts/
│ │ └── Base.astro # Base layout
│ └── components/ # Your Astro components
├── .emdash/
│ ├── seed.json # Template seed file
│ └── types.ts # Generated TypeScript types
└── package.json

ここでEmDashをAstro統合として設定します:

js title="astro.config.mjs"
import { defineConfig } from "astro/config";
import emdash, { local } from "emdash/astro";
import { sqlite } from "emdash/db";
export default defineConfig({
integrations: [
emdash({
database: sqlite({ url: "file:./data.db" }),
storage: local({
directory: "./uploads",
baseUrl: "/_emdash/api/media/file",
}),
}),
],
});

ここでEmDashをAstroのコンテンツシステムに接続します:

ts title="src/live.config.ts"
import { defineLiveCollection } from "astro:content";
import { emdashLoader } from "emdash/runtime";
export const collections = {
_emdash: defineLiveCollection({ loader: emdashLoader() }),
};

本番環境へのデプロイには、以下を設定する必要があります:

Terminal window
# Required for authentication
EMDASH_AUTH_SECRET=your-secret-here
# オプション: コンテンツプレビュー用
EMDASH_PREVIEW_SECRET=your-preview-secret

安全な認証シークレットを生成するには:

Terminal window
npx emdash auth secret

AstroページでEmDashのクエリ関数を使用します。これらはAstroのライブコレクションパターンに従い、コレクションには { entries, error } を、単一エントリーには { entry, error } を返します:

astro title="src/pages/index.astro"
---
import { getEmDashCollection } from "emdash";
import Base from "../../layouts/Base.astro";
const { entries: posts } = await getEmDashCollection("posts");
---
<Base title="ホーム">
<h1>最新の投稿</h1>
<ul>
{posts.map((post) => (
<li>
<a href={`/posts/${post.slug}`}>{post.data.title}</a>
</li>
))}
</ul>
</Base>

単一エントリーの場合:

astro title="src/pages/posts/[slug].astro"
---
import { getEmDashEntry } from "emdash";
const { slug } = Astro.params;
const { entry: post } = await getEmDashEntry("posts", slug);
if (!post) {
return Astro.redirect("/404");
}
---
<h1>{post.data.title}</h1>

完全な型安全性のために、データベーススキーマから型を生成します:

Terminal window
npx emdash types

これにより、すべてのコレクションのインターフェースを含む .emdash/types.ts が作成されます。エディタがフィールド名を自動補完し、型エラーを検出するようになります。

これで動作するEmDashサイトができました!次に進むべき場所は以下の通りです: