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

Greitasis startas

Įrašas apie schemas

Generuokite tipui saugias „Zod“ schemas

Ši funkcija leidžia gauti komponentų aprašą tipui saugios Zod schemos pavidalu, suteikdama:

  • „TypeScript-first“ schemos validaciją
  • Statinę tipų išvadą

Sužinokite daugiau: https://zod.dev

Sąranka

Norėdami gauti savo „Zod“ schemą, turėsite:

  1. Įkelkite reikiamas priklausomybes
  2. Sukurkite scenarijų naudojant cms-renderer įrankius

Projekto struktūra

apps/
  web/
    app/
      page.tsx
    scripts/
      generated-schema.ts   # scenarijaus failas

Scenarijus: 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 nenustatytas. Nustatykite jį savo aplinkoje arba .env faile.'
    );
  }

  if (!websiteId) {
    throw new Error(
      '[generate-schemas] CMS_WEBSITE_ID nenustatytas. Nustatykite jį savo aplinkoje arba .env faile.'
    );
  }

  if (!apiKey) {
    throw new Error(
      '[generate-schemas] PROFOUND_API_KEY nenustatytas. 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 galioja ir nukreipia į tinkamą svetainę.'
    );
  }

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

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

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

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

CMS konfigūracijos pavyzdys

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

package.json konfigūracija

Pastaba: jei neturite tsconfig.json, pašalinkite --tsconfig vėliavėlę.

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

Scenarijaus paleidimas

bun run generate-schemas

Pavyzdinė išvestis:

tsx --tsconfig tsconfig.json scripts/generate-schemas.ts
[generate-schemas] Rasta 3 komponentų: post, categories, header
[generate-schemas] Baigta.

Atnaujinta projekto struktūra

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

Naudojimas page.tsx

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

// Naudokite tipui saugiam analizavimui
petFoodPostSchema.parse(obj);

Pastabos

  • Peržiūrėkite sugeneruotą failą, kad suprastumėte savo komponento struktūrą
  • Iš naujo paleiskite scenarijų kiekvieną kartą, kai pasikeičia jūsų komponento struktūra:
bun run generate-schemas
  • Galite integruoti tai į savo kūrimo ar kompiliavimo darbo eigą
  • Atnaujinkite komponentus per administratoriaus skydą ir tuomet regeneruokite lokaliai
Continue Reading
NextSplit Screen JSON Component Builder with LLM›