Configuration
Every Keystatic project expects an exported config
. The config()
function can be imported from the @keystatic/core
package:
// keystatic.config.ts
import { config } from '@keystatic/core'
export default config({
// ...
})
Configuration options
Storage
The Keystatic config requires at minimum a storage
strategy. It's kind
can be set to:
- local to store and read files directly from your local file system
- github to connect to a GitHub repository and read/write files to it
- cloud to benefit from Keystatic Cloud's authentication and image hosting features
// keystatic.config.ts
import { config } from '@keystatic/core'
export default config({
storage: { kind: 'local' }
})
Branch prefix
If you're using the github
or cloud
storage kind, you can optionally set a branchPrefix
to scope out what branches Keystatic should interact with:
// keystatic.config.ts
import { config } from '@keystatic/core'
export default config({
storage: {
kind: 'github',
repo: 'Thinkmill/keystatic',
branchPrefix: 'my-prefix/'
}
})
Keystatic will only list branches starting with my-prefix/ in the Admin UI, and will only let you create new branches with that prefix.
Collections and singletons
The Keystatic config can also define collections
and singletons
:
// keystatic.config.ts
import { config } from '@keystatic/core'
export default config({
storage: { kind: 'local' } // required
collections: {
// posts...
// testimonials...
},
singletons: {
// settings...
// contactPage...
}
})
For more about collections
and sinlgetons
, check the Collections and Singletons pages.
Example usage
Here's an example of a Keystatic config
that creates a posts
collection, stored on the local file system within the src/content/posts
directory.
Each post has a title
as well as a long-form, WYSIWYG content
field.
// keystatic.config.ts
import { config, fields, collection } from '@keystatic/core';
export default config({
storage: {
kind: 'local',
},
collections: {
posts: collection({
label: 'Posts',
slugField: 'title',
path: 'src/content/posts/*',
format: { contentField: 'content' },
schema: {
title: fields.slug({ name: { label: 'Title' } }),
content: fields.document({
label: 'Content',
formatting: true,
dividers: true,
links: true,
images: true,
}),
},
}),
},
});
Type signature
Find the latest version of the config
type signature at: https://docsmill.dev/npm/@keystatic/core@latest#/.config