Update Keystatic configuration and documentation

Expanded Keystatic's configuration to support different storage kinds: local, cloud, and GitHub. Updated the README to explain the new configuration options, environment variables needed, and how to use storage kinds. Added external reference to Keystatic documentation for detailed concepts.
This commit is contained in:
giancarlo
2024-04-19 13:15:06 +08:00
parent 46f02f66eb
commit 27a717ad0f
2 changed files with 52 additions and 5 deletions

View File

@@ -6,4 +6,30 @@ This implementation is used when the host app's environment variable is set as:
```
CMS_CLIENT=keystatic
```
KEYSTATIC_PATH=content
```
Additionally, the following environment variables may be required:
```
KEYSTATIC_PATH=local # local, cloud, github
```
You can also use Keystatic Cloud or GitHub as the storage kind as remote storage.
If `KEYSTATIC_PATH_STORAGE_KIND` is set to `cloud`, the following environment variables are required:
```
KEYSTATIC_PATH_STORAGE_PROJECT=project-id
```
If `KEYSTATIC_PATH_STORAGE_KIND` is set to `github`, the following environment variables are required:
```
KEYSTATIC_PATH_STORAGE_REPO=repo-name
KEYSTATIC_PATH_STORAGE_BRANCH_PREFIX=branch-prefix
```
GitHub mode requires the installation of a GitHub app.
Please refer to the [Keystatic documentation](https://keystatic.com/docs/github-model) for more information.

View File

@@ -1,15 +1,36 @@
import { collection, config, fields } from '@keystatic/core';
import { z } from 'zod';
const path = z.string().parse(process.env.NEXT_PUBLIC_KEYSTATIC_CONTENT_PATH);
const local = z.object({
kind: z.literal('local'),
});
const cloud = z.object({
kind: z.literal('cloud'),
project: z.string(),
});
const github = z.object({
kind: z.literal('github'),
repo: z.custom<`${string}/${string}`>(),
branchPrefix: z.string().optional(),
});
const storage = z.union([local, cloud, github]).parse({
kind: process.env.KEYSTATIC_STORAGE_KIND ?? 'local',
project: process.env.KEYSTATIC_STORAGE_PROJECT,
repo: process.env.KEYSTATIC_STORAGE_REPO,
branchPrefix: process.env.KEYSTATIC_STORAGE_BRANCH_PREFIX,
githubToken: process.env.KEYSTATIC_GITHUB_TOKEN,
});
const path = process.env.KEY_STATIC_PATH ?? 'content';
export default createKeyStaticConfig(path);
function createKeyStaticConfig(path: string) {
return config({
storage: {
kind: 'local',
},
storage,
collections: {
posts: collection({
label: 'Posts',