Update Supabase version and improve Keystatic's configurations

This commit updates the version of Supabase in multiple packages. It also introduces specificity to environment variables in Keystatic configuration and adds a method to create a 'KeyStatic' reader based on the storage kind. Furthermore, minor adjustments have been made to keep the environment variable names consistent.
This commit is contained in:
giancarlo
2024-04-19 14:40:11 +08:00
parent d733c2e653
commit 19b8cc793e
15 changed files with 124 additions and 63 deletions

View File

@@ -1,4 +1,5 @@
import { collection, config, fields } from '@keystatic/core';
import { Entry } from '@keystatic/core/reader';
import { z } from 'zod';
const local = z.object({
@@ -14,19 +15,30 @@ const github = z.object({
kind: z.literal('github'),
repo: z.custom<`${string}/${string}`>(),
branchPrefix: z.string().optional(),
pathPrefix: z.string().optional(),
githubToken: z.string({
required_error: 'Please provide a GitHub token',
}),
});
const storage = z.union([local, cloud, github]).parse({
kind: process.env.KEYSTATIC_STORAGE_KIND ?? 'local',
kind: process.env.KEYSTATIC_STORAGE_KIND,
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,
pathPrefix: process.env.KEYSTATIC_PATH_PREFIX,
});
const path = process.env.KEY_STATIC_PATH ?? 'content';
export default createKeyStaticConfig(path);
const keyStaticConfig = createKeyStaticConfig(path);
export default keyStaticConfig;
export type PostEntryProps = Entry<
(typeof keyStaticConfig)['collections']['posts']
>;
function createKeyStaticConfig(path: string) {
return config({