Refactor and add generators for keystatic and package
The changes include refactoring the create-reader in cms keystatic and changing @keystatic/next version. Additionally, code generators for keystatic and package have been added, and corresponding templates have been organized into their respective directories.
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@keystatic/core": "0.5.14",
|
||||
"@keystatic/next": "5.0.0",
|
||||
"@keystatic/next": "^5.0.0",
|
||||
"@markdoc/markdoc": "^0.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -9,14 +9,10 @@ export async function createKeystaticReader() {
|
||||
switch (STORAGE_KIND) {
|
||||
case 'local': {
|
||||
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
||||
const path = await import('node:path');
|
||||
const { default: config } = await import('./keystatic.config');
|
||||
const { createReader } = await import('@keystatic/core/reader');
|
||||
|
||||
const contentPath = process.env.NEXT_PUBLIC_KEYSTATIC_CONTENT_PATH;
|
||||
const repositoryPath = path.join(process.cwd(), contentPath as string);
|
||||
|
||||
return createReader(repositoryPath, config);
|
||||
return createReader(process.cwd(), config);
|
||||
} else {
|
||||
// we should never get here but the compiler requires the check
|
||||
// to ensure we don't parse the package at build time
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from './keystatic-client';
|
||||
export * from './content-renderer';
|
||||
export * from './keystatic.config';
|
||||
|
||||
@@ -2,6 +2,6 @@ import { makeRouteHandler } from '@keystatic/next/route-handler';
|
||||
|
||||
import config from './keystatic.config';
|
||||
|
||||
export const { POST, GET } = makeRouteHandler({
|
||||
export const keystaticRouteHandlers = makeRouteHandler({
|
||||
config,
|
||||
});
|
||||
@@ -39,7 +39,9 @@ const storage = z.union([local, cloud, github]).parse({
|
||||
pathPrefix: process.env.KEYSTATIC_PATH_PREFIX,
|
||||
});
|
||||
|
||||
const keyStaticConfig = createKeyStaticConfig();
|
||||
const keyStaticConfig = createKeyStaticConfig(
|
||||
process.env.NEXT_PUBLIC_KEYSTATIC_CONTENT_PATH ?? 'content',
|
||||
);
|
||||
|
||||
export default keyStaticConfig;
|
||||
|
||||
@@ -75,14 +77,14 @@ export type PostEntryProps = Entry<
|
||||
(typeof keyStaticConfig)['collections']['posts']
|
||||
>;
|
||||
|
||||
function createKeyStaticConfig() {
|
||||
function createKeyStaticConfig(path: string) {
|
||||
return config({
|
||||
storage,
|
||||
collections: {
|
||||
posts: collection({
|
||||
label: 'Posts',
|
||||
slugField: 'title',
|
||||
path: `posts/*`,
|
||||
path: `${path}/posts/*`,
|
||||
format: { contentField: 'content' },
|
||||
schema: {
|
||||
title: fields.slug({ name: { label: 'Title' } }),
|
||||
@@ -107,7 +109,7 @@ function createKeyStaticConfig() {
|
||||
documentation: collection({
|
||||
label: 'Documentation',
|
||||
slugField: 'title',
|
||||
path: `documentation/**`,
|
||||
path: `${path}/documentation/**`,
|
||||
format: { contentField: 'content' },
|
||||
schema: {
|
||||
title: fields.slug({ name: { label: 'Title' } }),
|
||||
|
||||
Reference in New Issue
Block a user