diff --git a/CHANGELOG.md b/CHANGELOG.md index b300b217..f47b7150 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - [#370](https://github.com/estruyf/vscode-front-matter/issues/370): Define the tags and categories as reserved keywords for custom taxonomy - [#372](https://github.com/estruyf/vscode-front-matter/issues/372): Rename Taxonomy tab to Taxonomies - [#374](https://github.com/estruyf/vscode-front-matter/issues/374): Hide the front matter section to use the panel instead +- [#385](https://github.com/estruyf/vscode-front-matter/issues/385): If no default value for the draft field is defined, the field value will be set to `true` ### ⚡️ Optimizations diff --git a/src/helpers/ContentType.ts b/src/helpers/ContentType.ts index a407887c..3a54d6fb 100644 --- a/src/helpers/ContentType.ts +++ b/src/helpers/ContentType.ts @@ -576,6 +576,7 @@ export class ContentType { if (obj.fields) { const dateFormat = Settings.get(SETTING_DATE_FORMAT) as string; + for (const field of obj.fields) { if (field.name === "title") { if (field.default) { @@ -595,8 +596,16 @@ export class ContentType { if (typeof defaultValue === "string") { data[field.name] = processKnownPlaceholders(defaultValue, titleValue, dateFormat); data[field.name] = await ArticleHelper.processCustomPlaceholders(data[field.name], titleValue, filePath); + } else if (typeof defaultValue !== "undefined") { + data[field.name] = defaultValue; } else { - data[field.name] = typeof defaultValue !== "undefined" ? defaultValue : ""; + const draftField = ContentType.getDraftField(); + + if (field.type === "draft" && (draftField?.type === "boolean" || draftField?.type === undefined)) { + data[field.name] = true; + } else { + data[field.name] = ""; + } } } }