profound-logoProfound CMS
⌘K
Admin
Theme
DocsTutorialBlogPhilosophy
DocsTutorialBlogPhilosophy

Hybrid

Parametrinis maršrutizavimasKomponentų tipaiSetup server sent events (SSE) content refetchAdministratoriaus skydelio tarpinio serverio nustatymasSkriptų kūrimas šablonų kūrimo priemonėjeProject ScaffoldingMedia Library

Be sąsajos

Greitasis startasSplit Screen JSON Component Builder with LLMComponent Zod Pull

REST API

REST API apžvalgagetPrijunkite svetainę prie CMS APIgetGET /routesgetGauti maršrutągetGET /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 /usagepostPOST /csvpatchPATCH /csv
All Systems Operational
Powered Byprofound-logo
Theme

Component Zod Pull

Atsisiųskite Zod komponentų aprašą kompiliavimo metu naudodami scenarijų

Ši funkcija leidžia gauti jūsų komponento aprašą tipui saugios „Zod“ anotacijos forma, kuri suteikia TS-pirmo schemos tikrinimą ir statinį tipų išvedimą jūsų turiniui.

https://zod.dev

Norėdami nuskaityti mūsų Zod schemą, įkelsime kelias priklausomybes ir sukursime scenarijų, kuris naudoja keletą priemonių iš mūsų cms-renderer.

Pradėkime nuo mūsų projekto struktūros

apps/
 web/
 app/
   page.tsx
 scripts/
   generate-schemas.ts // čia saugomas mūsų scenarijus

Dabar redaguosime šį generated-schema.ts failą

import { fetchAllCustomSchemaFields, saveZodSchemaCode } from 'cms-renderer/lib/custom-schemas';
import { cmsConfig } from '../lib/cms-config'; // importuojame mano konfigūraciją

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

  if (!cmsUrl) {
    throw new Error(
      '[generate-schemas] NEXT_PUBLIC_CMS_API_URL nėra nustatytas. Nustatykite jį savo aplinkoje arba .env faile.'
    );
  }
  if (!websiteId) {
    throw new Error(
      '[generate-schemas] NEXT_PUBLIC_PROFOUND_WEBSITE_ID nėra nustatytas. Nustatykite jį savo aplinkoje arba .env faile.'
    );
  }
  if (!apiKey) {
    throw new Error(
      '[generate-schemas] PROFOUND_API_KEY nėra nustatytas. Nustatykite jį savo aplinkoje arba .env faile.'
    );
  }

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

  if (schemas.length === 0) {
    throw new Error(
      '[generate-schemas] API negrąžino jokių komponentų. Patikrinkite, ar PROFOUND_API_KEY yra teisingas ir nurodo tinkamą svetainę.'
    );
  }

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

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

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

Jūsų CmsConfig turėtų atrodyti taip

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

Savo package.json faile apibrėžiame, kaip paleisti scenarijų, ir nurodome kelias priklausomybes

PASTABA: Jeigu neturite tsconfig, galite pašalinti --tsconfig flagą ir jo reikšmę

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

Dabar, paleidę

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

Turėtume gauti panašų rezultatą ir mūsų projekto struktūroje matysime naują failą

apps/
 web/
 app/
   page.tsx
 scripts/
   generated-schema.ts // čia saugomas mūsų scenarijus
 generated/
   cms-schema.ts // sugeneruota zod schema

Galite jį peržiūrėti ir pamatyti, kaip atrodo jūsų schema. Norėdami atnaujinti šį failą, turite dar kartą paleisti komandą bun run generate-schemas, kurią galite prijungti prie savo dev arba build darbo eigos.

Tuomet galime importuoti šiuos zod objektus į mūsų page.tsx failą taip

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

// type saugiam objektų parsinimui kvieskite petFoodPostSchema.parse(obj)

Komponentą galite atnaujinti administratoriaus skydelyje ir vėl nuskaityti atnaujintą schemą, kad kūrimas būtų paprastesnis

Continue Reading
Previous‹Split Screen JSON Component Builder with LLM