From 951acd38a5305d991239d4e3c5f7bcf1949480ae Mon Sep 17 00:00:00 2001 From: giancarlo Date: Tue, 7 May 2024 19:51:05 +0700 Subject: [PATCH] Update default path and string manipulation in keystatic.config.ts A default path for createKeyStaticConfig function is added and conditional code block entered to append '/' to the path, if it doesn't end with it. This prevents potential path issues in future codes. Also, the default value of NEXT_PUBLIC_KEYSTATIC_CONTENT_PATH is changed to an empty string from 'content'. --- packages/cms/keystatic/src/keystatic.config.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/cms/keystatic/src/keystatic.config.ts b/packages/cms/keystatic/src/keystatic.config.ts index 2b5cb1354..cbef49825 100644 --- a/packages/cms/keystatic/src/keystatic.config.ts +++ b/packages/cms/keystatic/src/keystatic.config.ts @@ -40,7 +40,7 @@ const storage = z.union([local, cloud, github]).parse({ }); const keyStaticConfig = createKeyStaticConfig( - process.env.NEXT_PUBLIC_KEYSTATIC_CONTENT_PATH ?? 'content', + process.env.NEXT_PUBLIC_KEYSTATIC_CONTENT_PATH ?? '', ); export default keyStaticConfig; @@ -77,14 +77,18 @@ export type PostEntryProps = Entry< (typeof keyStaticConfig)['collections']['posts'] >; -function createKeyStaticConfig(path: string) { +function createKeyStaticConfig(path = '') { + if (path && !path.endsWith('/')) { + path += '/'; + } + return config({ storage, collections: { posts: collection({ label: 'Posts', slugField: 'title', - path: `${path}/posts/*`, + path: `${path}posts/*`, format: { contentField: 'content' }, schema: { title: fields.slug({ name: { label: 'Title' } }), @@ -109,7 +113,7 @@ function createKeyStaticConfig(path: string) { documentation: collection({ label: 'Documentation', slugField: 'title', - path: `${path}/documentation/**`, + path: `${path}documentation/**`, format: { contentField: 'content' }, schema: { title: fields.slug({ name: { label: 'Title' } }),