Skip to content

Commit 1d0e61f

Browse files
committed
feat(index-fields): allow defining own field schema for index files
1 parent 8b8e873 commit 1d0e61f

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

packages/decap-cms-core/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ declare module 'decap-cms-core' {
323323

324324
frontmatter_delimiter?: string[] | string;
325325
fields?: CmsField[];
326+
index_fields?: CmsField[];
326327
filter?: { field: string; value: any };
327328
path?: string;
328329
media_folder?: string;

packages/decap-cms-core/src/constants/configSchema.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ function getConfigSchema() {
242242
},
243243
},
244244
fields: fieldsConfig(),
245+
index_fields: fieldsConfig(),
245246
sortable_fields: {
246247
type: 'array',
247248
items: {

packages/decap-cms-core/src/reducers/collections.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ function collections(state = defaultState, action: ConfigAction) {
4343
}
4444
}
4545

46+
function isIndexFile(filePath: string) {
47+
const fileSlug = filePath?.split('/').pop();
48+
const indexFiles = Set(['_index', 'index']);
49+
50+
return fileSlug && indexFiles.has(fileSlug);
51+
}
52+
4653
const selectors = {
4754
[FOLDER]: {
4855
entryExtension(collection: Collection) {
@@ -55,7 +62,10 @@ const selectors = {
5562

5663
return ext.replace(/^\./, '');
5764
},
58-
fields(collection: Collection) {
65+
fields(collection: Collection, slug: string) {
66+
if (collection.get('index_fields') && isIndexFile(slug)) {
67+
return collection.get('index_fields');
68+
}
5969
return collection.get('fields');
6070
},
6171
entryPath(collection: Collection, slug: string) {

packages/decap-cms-core/src/types/redux.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ type CollectionObject = {
607607
folder?: string;
608608
files?: CollectionFiles;
609609
fields: EntryFields;
610+
index_fields?: EntryFields;
610611
isFetching: boolean;
611612
media_folder?: string;
612613
public_folder?: string;

0 commit comments

Comments
 (0)