-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathcollections.mdoc
169 lines (124 loc) · 4.44 KB
/
collections.mdoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
---
title: Collections
summary: >-
Think of a collection as anything you’d want multiple instances of. A series
of blog posts, cooking recipes, or testimonials from happy customers.
---
Think of a `collection` as anything you’d want multiple instances of. A series of blog posts, cooking recipes, or testimonials from happy customers.
Collections are defined within the `collections` key of the Keystatic `config`. Each collection has its own key and is wrapped in a `collection()` function.
## Example
Here’s how you’d define a `testimonial` collection, where each entry has an `author` and a `quote` fields:
```jsx
// keystatic.config.ts
import { config, collection } from '@keystatic/core';
export default config({
// ...
collections: {
testimonials: collection({
label: 'Testimonials',
slugField: 'author',
schema: {
author: fields.slug({ name: { label: 'Author' } }),
quote: fields.text({ label: 'Quote', multiline: true })
}
}),
},
});
```
---
## Options
### Columns
By default, only the “slug” of each entry is displayed in the collection table. You can show additional fields by passing a `columns` option.
{% aside icon="⏱️" %}
Fetching data for each entry takes time. Large collections may benefit from displaying the slug only.
{% /aside %}
#### Basic columns
Pass an array of field keys to show them in the collection table:
```ts
columns: ['title', 'publishedOn']
```
#### Columns definition
For more control, use a `columns` object with a `definition` array. Column definitions require a `defaultSort` option.
```ts
columns: {
definition: [
{ key: 'title', isRowHeader: true },
{
key: 'publishedOn',
label: 'Published',
width: 140,
align: 'end'
},
],
defaultSort: {
column: 'publishedOn',
direction: 'descending'
}
}
```
{% table %}
- Property
- Description
---
- `align`
- The alignment of the column’s contents relative to its allotted width.
---
- `allowsSorting`
- Whether the column allows sorting. Defaults to `true`.
---
- `isRowHeader`
- Whether a column is a [row header](https://www.w3.org/TR/wai-aria-1.1/#rowheader) and should be announced by assistive technology during row navigation.
---
- `key` (required)
- The key of the column.
---
- `label`
- The label of the column. Defaults to the label of the matching schema field, by `key`.
---
- `maxWidth`
- The maximum width of the column.
---
- `minWidth`
- The minimum width of the column.
---
- `width`
- The width of the column.
{% /table %}
### Label
`label` — defines the name of the collection. This is used in the Admin UI to label the collection.
### Entry layout
`entryLayout` — change the layout of the Admin UI for a collection entry.
Learn more on the [Entry Layout](/docs/entry-layout) page.
### Format
`format` — provides options around the data format of your collection entries.
Learn more on the [Format Options](/docs/format-options) page.
### Path
`path` — allows you to you specify *where* to store entries for any given collection:
```tsx
path: 'custom/content/path/testimonials/*'
```
By default, Keystatic will store entries at the root of your project, in a directory that matches the collection key.
You can learn more about the `path` option on the [Content organisation page](/docs/content-organisation).
### Parse slug for sort
`parseSlugForSort` — a function to transform the `slug` of each entry into a value to be used for sorting the collection list view.
### Preview URL
`previewURL` — used to configure [Real-time Previews](/docs/recipes/real-time-previews) of your content.
### Schema
`schema` — defines the fields that each entry in the collection should have.
### Slug field
`slugField` — defines what field in your collection `schema` should be used as the slug for each item.
It’s recommended to combine it with the [slug field](/docs/fields/slug) to let users customise and regenerate each slug in the Admin UI.
```typescript
testimonials: collection({
label: 'Testimonials',
schema: {
title: fields.slug({ name: { label: 'Title' } }),
},
slugField: 'title',
}),
```
### Template
`template` — the path to a content file (existing collection entry or “template”) to use as a starting point for new entries.
---
## Type signature
Find the latest version of the `Collection` type signature at: [https://docsmill.dev/npm/@keystatic/core@latest#/.Collection](https://docsmill.dev/npm/@keystatic/core@latest#/.Collection)