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

Component Zod Pull

Stiahnite si popis zod svojich komponentov v čase kompilácie pomocou skriptu

Táto funkcia vám umožňuje získať popis vášho komponentu vo forme typovo bezpečného popisu „Zod“, ktorý poskytuje validáciu schémy orientovanú na „TS-first“ a statickú inferenciu typov pre váš obsah.

https://zod.dev

Aby sme stiahli našu schému Zod, načítame niektoré závislosti a vytvoríme skript, ktorý používa niektoré utility z nášho cms-renderer

Začnime štruktúrou nášho projektu

apps/
 web/
 app/
   page.tsx
 scripts/
   generate-schemas.ts // this is where our script lives

Teraz upravíme súbor generated-schema.ts

import { fetchAllCustomSchemaFields, saveZodSchemaCode } from 'cms-renderer/lib/custom-schemas';
import { cmsConfig } from '../lib/cms-config'; // importing my 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] NEXT_PUBLIC_PROFOUND_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.'
    );
  }

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

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

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

CmsConfig by mal vyzerať takto

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

V súbore package.json definujeme, ako sa skript spúšťa, a niektoré závislosti

POZNÁMKA: Ak nemáte tsconfig, môžete odstrániť príznak --tsconfig a jeho hodnotu

{
  "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",
    "...": "..."
  }
}

Teraz, po spustení

$ bun run generate-schemas
tsx --tsconfig tsconfig.json scripts/generate-schemas.ts
[generate-schemas] Done.

Mali by sme dostať podobný výstup a v štruktúre projektu uvidíme nový súbor

apps/
 web/
 app/
   page.tsx
 scripts/
   generated-schema.ts // this is where our script lives
 generated/
   cms-schema.ts // generated zod schema

Môžete sa pozrieť dovnútra a uvidíte, ako vyzerá vaša schéma. Ak chcete tento súbor aktualizovať, musíte znova spustiť príkaz bun run generate-schemas, ktorý môžete napojiť na svoj dev alebo build workflow.

Potom môžeme tieto objekty zod natiahnuť do súboru page.tsx takto

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

// call petFoodPostSchema.parse(obj) for type safe parsing of objects

Svoj komponent môžete aktualizovať z administračného panela a pre jednoduchý vývoj znovu stiahnuť aktualizovanú schému

Continue Reading
Previous‹Split Screen JSON Component Builder with LLM