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 proxySkriptovanie v nástroji na tvorbu šablónProject ScaffoldingKnižnica médií

Headless

Rýchly štartSplit Screen JSON Component Builder with LLMComponent Zod Pull

REST API

Prehľad REST APIgetConnect your websitegetZískanie trásgetZískanie trasygetZískaj blokygetGET /blocks/with-cel-cachegetGET /blocks/generatedgetGET /componentsgetGET /components/{name}getGET /dataset/{schema_name}getGET /content-changes (SSE)patchPATCH /dataset/{schema_name}postPOST /translationpatchPATCH /translationsgetGET /usagepostPOST /csvpatchPATCH /csv
All Systems Operational
Powered Byprofound-logo
Theme

Rýchly štart

Príspevok o schémach

Generujte typovo bezpečné schémy Zod

Táto funkcia vám umožňuje získať popis vašich komponentov vo forme typovo bezpečnej schémy Zod, ktorá poskytuje:

  • Validáciu schém orientovanú na TypeScript
  • Statické odvodenie typov

Zistite viac: https://zod.dev

Nastavenie

Ak chcete získať svoju schému Zod, budete musieť:

  1. Načítajte potrebné závislosti
  2. Vytvorte skript využívajúci utility z cms-renderer

Štruktúra projektu

apps/
  web/
    app/
      page.tsx
    scripts/
      generated-schema.ts   # script file

Skript: 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 is not set. Set it in your environment or .env file.'
    );
  }

  if (!websiteId) {
    throw new Error(
      '[generate-schemas] CMS_WEBSITE_ID is not set. Set it in your environment or .env file.'
    );
  }

  if (!apiKey) {
    throw new Error(
      '[generate-schemas] PROFOUND_API_KEY is not set. Set it in your environment or .env file.'
    );
  }

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

  if (schemas.length === 0) {
    throw new Error(
      '[generate-schemas] No components returned from the API. Check that PROFOUND_API_KEY is valid and points at the right website.'
    );
  }

  console.log(
    `[generate-schemas] Found ${schemas.length} components: ${schemas.map((s) => s.name).join(', ')}`
  );

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

  console.log('[generate-schemas] Done.');
}

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

Príklad konfigurácie CMS

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

Konfigurácia package.json

Poznámka: Ak nemáte súbor tsconfig.json, odstráňte príznak --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",
    "...": "..."
  }
}

Spustenie skriptu

bun run generate-schemas

Ukážkový výstup:

tsx --tsconfig tsconfig.json scripts/generate-schemas.ts
[generate-schemas] Found 3 components: post, categories, header
[generate-schemas] Done.

Aktualizovaná štruktúra projektu

apps/
  web/
    app/
      page.tsx
    scripts/
      generated-schema.ts
    generated/
      cms-schemas.ts   # generated Zod schema

Použitie v page.tsx

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

// Použite na typovo bezpečné parsovanie
petFoodPostSchema.parse(obj);

Poznámky

  • Skontrolujte vygenerovaný súbor, aby ste porozumeli štruktúre svojho komponentu
  • Spustite skript znova vždy, keď sa štruktúra vášho komponentu zmení:
bun run generate-schemas
  • Tento proces môžete integrovať do svojho vývojového alebo build procesu
  • Aktualizujte komponenty prostredníctvom administračného panela a potom ich regenerujte lokálne
Continue Reading
NextSplit Screen JSON Component Builder with LLM›