Update KEYSTATIC paths and storage handling
The code now reads storage type from a constant instead of directly from the environment variable. It also checks if `NEXT_RUNTIME` is `nodejs` before parsing Keystatic config and core reader. The `README.md` and `keystatic.config.ts` were updated to handle a new environment variable `KEYSTATIC_CONTENT_PATH` for custom content paths.
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const STORAGE_KIND = process.env.KEYSTATIC_STORAGE_KIND ?? 'local';
|
||||
|
||||
/**
|
||||
* Create a KeyStatic reader based on the storage kind.
|
||||
*/
|
||||
export async function createKeystaticReader() {
|
||||
switch (process.env.KEYSTATIC_STORAGE_KIND ?? 'local') {
|
||||
switch (STORAGE_KIND) {
|
||||
case 'local': {
|
||||
const { default: config } = await import('./keystatic.config');
|
||||
const { createReader } = await import('@keystatic/core/reader');
|
||||
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
||||
const { default: config } = await import('./keystatic.config');
|
||||
const { createReader } = await import('@keystatic/core/reader');
|
||||
|
||||
return createReader('.', config);
|
||||
return createReader('.', config);
|
||||
} else {
|
||||
// we should never get here but the compiler requires the check
|
||||
// to ensure we don't parse the package at build time
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
|
||||
case 'github':
|
||||
|
||||
@@ -30,7 +30,7 @@ const storage = z.union([local, cloud, github]).parse({
|
||||
pathPrefix: process.env.KEYSTATIC_PATH_PREFIX,
|
||||
});
|
||||
|
||||
const path = process.env.KEY_STATIC_PATH ?? 'content';
|
||||
const path = process.env.KEYSTATIC_CONTENT_PATH ?? 'content';
|
||||
|
||||
const keyStaticConfig = createKeyStaticConfig(path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user