Skip to content

Commit

Permalink
feat(index-fields): differentiate nested/non-nested collections
Browse files Browse the repository at this point in the history
  • Loading branch information
demshy committed Feb 6, 2025
1 parent 4c99ad1 commit db6b1b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function mapStateToProps(state, ownProps) {
const isLoadingAsset = selectIsLoadingAsset(state.medias);

const indexFileConfig = collection.get('index_file');
const fileSlug = entry.get('slug')?.split('/').pop();
const fileSlug = entry.get('slug');

return {
summary,
Expand Down
6 changes: 3 additions & 3 deletions packages/decap-cms-core/src/reducers/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function collections(state = defaultState, action: ConfigAction) {
}
}

function isIndexFile(filePath: string, pattern: string) {
const fileSlug = filePath?.split('/').pop();
function isIndexFile(filePath: string, pattern: string, nested: boolean) {
const fileSlug = nested ? filePath?.split('/').pop() : filePath;
return fileSlug && new RegExp(pattern).test(fileSlug);
}

Expand All @@ -64,7 +64,7 @@ const selectors = {
const indexFileConfig = collection.get('index_file');
if (
indexFileConfig &&
isIndexFile(slug, indexFileConfig.get('pattern')) &&
isIndexFile(slug, indexFileConfig.get('pattern'), !!collection.get('nested')) &&
indexFileConfig.has('fields')
) {
return indexFileConfig.get('fields');
Expand Down

0 comments on commit db6b1b0

Please sign in to comment.