From be93beda7e1bdab0bf9d2f9e15dd326c4959f514 Mon Sep 17 00:00:00 2001 From: David Enke Date: Sat, 14 Dec 2024 13:31:27 +0100 Subject: [PATCH] docs: remove programmatic (runtime) usage from readme --- README.md | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/README.md b/README.md index 678569d..7c928a1 100644 --- a/README.md +++ b/README.md @@ -21,22 +21,10 @@ pnpm add -D astro-decap-collection yarn add -D astro-decap-collection ``` -## Usage - -This module can either be used as a CLI tool or as a programmatic library. - -| cli | programmatic | -| ----------------------------------------------------------- | ------------------------------------------------------------------- | -| 1. Run cli tool to generate the zod schema | 1. Load or import your Decap config file manually | -| 2. Load the generated schema in the Astro collection config | 2. Transform Decap config into zod schema | -| | 3. Provide the zod schema at runtime in the Astro collection config | - -### Cli usage +### Usage Transform the Decap config at build time and use the generated Zod schema. This allows Astro to validate the given data and provides types as well. -> This is the recommended way to use this module. - | Option | Description | | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | `--config`, `-c` | Path to the Decap YML config file, can be a [glob pattern](https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#pattern-syntax) | @@ -90,31 +78,6 @@ For the time being, the following placeholders are supported: - `%%name%%` - The name of the collection from the Decap config -### Programmatic usage - -This wont get you types, but you can still validate content against the schema. - -```typescript -import { - getCollection, - loadDecapConfig, - prepareSchema, - transformCollection, -} from 'astro-decap-collection'; -import { defineCollection, z as zod } from 'astro:content'; -import { fileURLToPath } from 'node:url'; - -// load Decap config and transform it at runtime -const configURL = fileURLToPath(new URL('../../public/admin/config.yml', import.meta.url)); -const config = await loadDecapConfig(configURL); -const collection = getCollection(config, 'blog')!; -const schema = await transformCollection(collection, { zod }); - -export const collections = { - blog: defineCollection(prepareSchema(schema.runtime)), -}; -``` - ## Local development Run a local tsx compiler in watch mode