#385: Add a default draft field value

This commit is contained in:
Elio Struyf
2022-08-11 17:52:36 +02:00
parent 4a8bbaf82e
commit 1766c19133
2 changed files with 11 additions and 1 deletions
+1
View File
@@ -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
+10 -1
View File
@@ -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] = "";
}
}
}
}