mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-06 08:52:47 +02:00
Add support for field groups + block fields #808
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
- [#798](https://github.com/estruyf/vscode-front-matter/issues/798): Changed dialog to slide-over for the snippet forms
|
||||
- [#799](https://github.com/estruyf/vscode-front-matter/issues/799): Added `frontMatter.logging` setting to define the logging output. Options are `info`, `warn`, `error`, and `verbose`. Default is `info`.
|
||||
- [#800](https://github.com/estruyf/vscode-front-matter/issues/800): Add colors for the Front Matter CMS output
|
||||
- [#808](https://github.com/estruyf/vscode-front-matter/issues/808): Add support to generate field groups and `block` fields in content type generation
|
||||
- [#810](https://github.com/estruyf/vscode-front-matter/issues/810): Update the tab title based on the view
|
||||
|
||||
### ⚡️ Optimizations
|
||||
|
||||
@@ -280,7 +280,7 @@ export class ContentType {
|
||||
pageBundle = pageBundleAnswer === l10n.t(LocalizationKey.commonYes);
|
||||
}
|
||||
|
||||
const fields = ContentType.generateFields(content.data);
|
||||
const fields = await ContentType.generateFields(content.data);
|
||||
|
||||
// Update the type field in the page
|
||||
if (!overrideBool && editor) {
|
||||
@@ -344,7 +344,7 @@ export class ContentType {
|
||||
}
|
||||
|
||||
const contentType = await ArticleHelper.getContentType(article);
|
||||
const updatedFields = ContentType.generateFields(article.data, contentType.fields);
|
||||
const updatedFields = await ContentType.generateFields(article.data, contentType.fields);
|
||||
|
||||
const contentTypes = ContentType.getAll() || [];
|
||||
const index = contentTypes.findIndex((ct) => ct.name === contentType.name);
|
||||
@@ -744,7 +744,7 @@ export class ContentType {
|
||||
* @param fields
|
||||
* @returns
|
||||
*/
|
||||
private static generateFields(data: any, fields: any[] = []) {
|
||||
private static async generateFields(data: any, fields: any[] = []) {
|
||||
for (const field in data) {
|
||||
const fieldData = data[field];
|
||||
|
||||
@@ -782,15 +782,38 @@ export class ContentType {
|
||||
fieldData.length > 0 &&
|
||||
typeof fieldData[0] === 'object'
|
||||
) {
|
||||
const newFields = ContentType.generateFields(fieldData);
|
||||
const newFields = await ContentType.generateFields(fieldData);
|
||||
|
||||
// Combine all the fields for the field group
|
||||
const blockFields: Field[] = [];
|
||||
for (const newField of newFields) {
|
||||
for (const field of newField.fields) {
|
||||
if (blockFields.some((f) => f.name === field.name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
blockFields.push(field);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate a new field group
|
||||
const fieldGroups = Settings.get<FieldGroup[]>(SETTING_TAXONOMY_FIELD_GROUPS) || [];
|
||||
const fieldGroupName = `${field}_group`;
|
||||
const newFieldGroup: FieldGroup = {
|
||||
id: fieldGroupName,
|
||||
fields: blockFields
|
||||
};
|
||||
fieldGroups.push(newFieldGroup);
|
||||
await Settings.update(SETTING_TAXONOMY_FIELD_GROUPS, fieldGroups, true);
|
||||
|
||||
fields.push({
|
||||
title: field,
|
||||
name: field,
|
||||
type: 'block',
|
||||
fields: newFields
|
||||
fieldGroup: [fieldGroupName]
|
||||
} as Field);
|
||||
} else if (fieldData && fieldData instanceof Object) {
|
||||
const newFields = ContentType.generateFields(fieldData);
|
||||
const newFields = await ContentType.generateFields(fieldData);
|
||||
fields.push({
|
||||
title: field,
|
||||
name: field,
|
||||
|
||||
Reference in New Issue
Block a user