feat(yaml): support comments (#3529)

This commit is contained in:
Erez Rokah
2020-04-07 15:00:06 +03:00
committed by GitHub
parent 4489b6ff49
commit 4afbbdd8a9
98 changed files with 458 additions and 185 deletions

View File

@ -404,4 +404,24 @@ export const selectSortDataPath = (collection: Collection, key: string) => {
}
};
export const selectFieldsComments = (collection: Collection, entryMap: EntryMap) => {
let fields: EntryField[] = [];
if (collection.has('folder')) {
fields = collection.get('fields').toArray();
} else if (collection.has('files')) {
const file = collection.get('files')!.find(f => f?.get('name') === entryMap.get('slug'));
fields = file.get('fields').toArray();
}
const comments: Record<string, string> = {};
const names = getFieldsNames(fields);
names.forEach(name => {
const field = selectField(collection, name);
if (field?.has('comment')) {
comments[name] = field.get('comment')!;
}
});
return comments;
};
export default collections;