profound-logoProfound CMS
⌘K
Admin
Theme
DocsTutorialBlogPhilosophy
DocsTutorialBlogPhilosophy

Hybrid

Collection of Pages with ComponentsTypes of ComponentsSetup server sent events (SSE) content refetchInstall Profound CMS as a proxyCEL Scripting in Template BuilderProject ScaffoldingMedia Library

Headless

Quick startSplit Screen JSON Component Builder with LLMComponent Zod Pull

REST API

REST API 概要getウェブサイトを CMS API に接続するgetGET /routesgetGET /routegetGET /blocksgetGET /blocks/with-cel-cachegetGET /blocks/generatedgetGET /componentsgetGET /components/{name}getGET /dataset/{schema_name}getGET /content-changes (SSE)patchPATCH /dataset/{schema_name}postPOST /translationpatchPATCH /translationsgetGET /usagepostCSV 投稿patchPATCH /csv
All Systems Operational
Powered Byprofound-logo
Theme

Quick start

スキーマについての記事

型安全な Zod スキーマを生成する

この機能を使用すると、コンポーネントの説明を型安全な Zod スキーマとして取得でき、次の利点があります:

  • TypeScript を第一としたスキーマ検証
  • 静的型推論

詳細はこちら: https://zod.dev

セットアップ

Zod スキーマを取得するには、次の手順を実行します。

  1. 必要な依存関係を読み込む
  2. cms-renderer のユーティリティを使用してスクリプトを作成する

プロジェクト構成

apps/
  web/
    app/
      page.tsx
    scripts/
      generated-schema.ts   # スクリプトファイル

スクリプト: generated-schema.ts

import { fetchAllCustomSchemaFields, saveZodSchemaCode } from 'cms-renderer/lib/custom-schemas';
import { cmsConfig } from '../lib/cms-config';

async function main() {
  const { cmsUrl, websiteId, apiKey } = cmsConfig;

  if (!cmsUrl) {
    throw new Error(
      '[generate-schemas] NEXT_PUBLIC_CMS_API_URL が設定されていません。環境変数または .env ファイルで設定してください。'
    );
  }

  if (!websiteId) {
    throw new Error(
      '[generate-schemas] CMS_WEBSITE_ID が設定されていません。環境変数または .env ファイルで設定してください。'
    );
  }

  if (!apiKey) {
    throw new Error(
      '[generate-schemas] PROFOUND_API_KEY が設定されていません。環境変数または .env ファイルで設定してください。'
    );
  }

  const schemas = await fetchAllCustomSchemaFields({ cmsUrl, websiteId, apiKey });

  if (schemas.length === 0) {
    throw new Error(
      '[generate-schemas] API からコンポーネントが返されませんでした。PROFOUND_API_KEY が有効で、正しいウェブサイトを指していることを確認してください。'
    );
  }

  console.log(
    `[generate-schemas] ${schemas.length} 個のコンポーネントを検出しました: ${schemas.map((s) => s.name).join(', ')}`
  );

  await saveZodSchemaCode(schemas, './generated/cms-schemas.ts');

  console.log('[generate-schemas] 完了しました。');
}

main().catch((err) => {
  console.error('[generate-schemas] 失敗しました:', err);
  process.exit(1);
});

CMS 設定例

export const cmsConfig = {
  cmsUrl: process.env.NEXT_PUBLIC_CMS_API_URL,
  apiKey: process.env.CMS_API_KEY,
  websiteId: '...',
};

package.json の設定

注意: tsconfig.json がない場合は、--tsconfig フラグを削除してください。

{
  "name": "web",
  "version": "0.1.0",
  "type": "module",
  "private": true,
  "scripts": {
    "generate-schemas": "tsx --tsconfig tsconfig.json scripts/generate-schemas.ts",
    "...": "..."
  },
  "dependencies": {
    "cms-renderer": "0.3.1",
    "zod": "^4.3.6",
    "...": "..."
  },
  "devDependencies": {
    "tsx": "^4.21.0",
    "object-hash": "^3.0.0",
    "...": "..."
  }
}

スクリプトの実行

bun run generate-schemas

出力例:

tsx --tsconfig tsconfig.json scripts/generate-schemas.ts
[generate-schemas] 3 個のコンポーネントを検出しました: post, categories, header
[generate-schemas] 完了しました。

更新されたプロジェクト構成

apps/
  web/
    app/
      page.tsx
    scripts/
      generated-schema.ts
    generated/
      cms-schemas.ts   # 生成された Zod スキーマ

page.tsx での使用例

import type { PetFoodPost, SiteConfig } from '@/generated/cms-schemas';
import { petFoodPostSchema } from '@/generated/cms-schemas';

// 型安全なパースに使用します
petFoodPostSchema.parse(obj);

注意事項

  • 生成されたファイルを確認し、コンポーネントの構造を把握してください。
  • コンポーネントの構造が変わるたびにスクリプトを再実行してください:
bun run generate-schemas
  • 開発またはビルドのワークフローに統合することもできます。
  • 管理パネル経由でコンポーネントを更新し、その後ローカルで再生成してください。
Continue Reading
NextSplit Screen JSON Component Builder with LLM›