セクション
セクションは、編集者がスラッシュコマンドを通じて任意のコンテンツに挿入できる再利用可能なコンテンツブロックです。CTA、お客様の声、機能グリッド、または複数のページにまたがって表示される共通パターンに使用します。
セクションのクエリ
Section titled “セクションのクエリ”getSection
Section titled “getSection”スラッグで単一のセクションを取得:
import { getSection } from "emdash";
const cta = await getSection("newsletter-cta");
if (cta) { console.log(cta.title); // "Newsletter CTA" console.log(cta.content); // PortableTextBlock[]}getSections
Section titled “getSections”オプションのフィルターを使用して複数のセクションを取得:
import { getSections } from "emdash";
// すべてのセクションを取得const { items: all } = await getSections();
// ソースでフィルターconst { items: themeSections } = await getSections({ source: "theme" });
// タイトル/キーワードで検索const { items: results } = await getSections({ search: "newsletter" });getSections は標準のページネーションパターンに従って { items: Section[], nextCursor?: string } を返します。
セクションの構造
Section titled “セクションの構造”interface Section { id: string; slug: string; title: string; description?: string; keywords: string[]; content: PortableTextBlock[]; previewUrl?: string; source: "theme" | "user" | "import"; themeId?: string; createdAt: string; updatedAt: string;}ソースタイプ
Section titled “ソースタイプ”| ソース | 説明 |
|---|---|
theme | シードファイルで定義、テーマによって管理 |
user | 管理者で編集者によって作成 |
import | WordPress(再利用可能ブロック)からインポート |
コンテンツでのセクションの使用
Section titled “コンテンツでのセクションの使用”編集者はリッチテキストエディター内で /section スラッシュコマンドを使用してセクションを挿入します:
-
/section(または/pattern、/block、/template)と入力 -
利用可能なセクションを検索または閲覧
-
クリックしてカーソル位置にセクションのコンテンツを挿入
セクションのPortable Textコンテンツがドキュメントにコピーされます。これは次のことを意味します:
- セクションへの変更は、既に挿入されたコンテンツに影響しません
- 編集者は挿入されたコンテンツをカスタマイズできます
- コンテンツは自己完結型のままです
セクションの作成
Section titled “セクションの作成”-
管理サイドバーの セクション に移動
-
新規セクション をクリック
-
以下を入力:
- タイトル - セクションの表示名
- スラッグ - URL識別子(タイトルから自動生成)
- 説明 - 編集者向けのヘルプテキスト
-
リッチテキストエディターを使用してコンテンツを追加
-
必要に応じて、検索を容易にするためのキーワードを設定
シードファイル経由
Section titled “シードファイル経由”テーマのシードファイルにセクションを含めます:
{ "sections": [ { "slug": "hero-centered", "title": "Centered Hero", "description": "Full-width hero with centered heading and CTA", "keywords": ["hero", "banner", "header"], "content": [ { "_type": "block", "style": "h1", "children": [{ "_type": "span", "text": "私たちのサイトへようこそ" }] }, { "_type": "block", "children": [{ "_type": "span", "text": "Your tagline goes here." }] } ] }, { "slug": "newsletter-cta", "title": "Newsletter CTA", "keywords": ["newsletter", "subscribe", "email"], "content": [ { "_type": "block", "style": "h3", "children": [{ "_type": "span", "text": "Subscribe to our newsletter" }] } ] } ]}WordPressインポート経由
Section titled “WordPressインポート経由”WordPressの再利用可能ブロック(wp_block 投稿タイプ)は自動的にセクションとしてインポートされます:
- ソースは
"import"に設定されます - GutenbergコンテンツはPortable Textに変換されます
プログラムによるセクションのレンダリング
Section titled “プログラムによるセクションのレンダリング”エディター外でサーバーサイドレンダリングされるセクションコンテンツの場合:
---import { getSection } from "emdash";import { PortableText } from "emdash/ui";
const newsletter = await getSection("newsletter-cta");---
{newsletter && ( <aside class="cta-box"> <PortableText value={newsletter.content} /> </aside>)}管理UIの機能
Section titled “管理UIの機能”セクションライブラリ(/_emdash/admin/sections)は以下を提供します:
- セクションプレビュー付きの グリッドビュー
- タイトルとキーワードによる 検索
- ソースによる フィルター
- スラッグの クイックコピー をクリップボードへ
- セクションコンテンツとメタデータの 編集
- 確認付きの 削除(テーマセクションには警告が表示されます)
APIリファレンス
Section titled “APIリファレンス”getSection(slug)
Section titled “getSection(slug)”スラッグでセクションを取得します。
パラメータ:
slug— セクションの一意の識別子(文字列)
戻り値: Promise<Section | null>
getSections(options?)
Section titled “getSections(options?)”オプションのフィルターを使用してセクションを一覧表示します。
パラメータ:
options.source— ソースでフィルター:"theme"、"user"、または"import"options.search— タイトルとキーワードを検索
戻り値: Promise<Section[]>
REST API
Section titled “REST API”セクションの一覧
Section titled “セクションの一覧”GET /_emdash/api/sectionsGET /_emdash/api/sections?source=themeGET /_emdash/api/sections?search=newsletterセクションの取得
Section titled “セクションの取得”GET /_emdash/api/sections/newsletter-ctaセクションの作成
Section titled “セクションの作成”POST /_emdash/api/sectionsContent-Type: application/json
{ "slug": "my-section", "title": "My Section", "description": "Optional description", "keywords": ["keyword1", "keyword2"], "content": [...]}セクションの更新
Section titled “セクションの更新”PUT /_emdash/api/sections/my-sectionContent-Type: application/json
{ "title": "Updated Title", "content": [...]}セクションの削除
Section titled “セクションの削除”DELETE /_emdash/api/sections/my-section次のステップ
Section titled “次のステップ”- コンテンツの操作 - リッチテキストエディターについて学ぶ
- ウィジェットエリア - 同期された動的コンテンツ用
- コンテンツインポート - WordPressの再利用可能ブロックをインポート