From f059b89fa5bfdc2c6f69fb7aa3436f83d1d8b0ef Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 4 Apr 2022 08:35:18 +0200 Subject: [PATCH] #306 - Default value fix --- CHANGELOG.md | 1 + package.json | 2 +- src/helpers/ContentType.ts | 10 ++++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b7ce3a6..539fd0c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - [#302](https://github.com/estruyf/vscode-front-matter/issues/302): Fix for spinner when navigating between tabs - [#304](https://github.com/estruyf/vscode-front-matter/issues/304): Fix yaml stringify which caused additional fields to be added - [#305](https://github.com/estruyf/vscode-front-matter/issues/305): Fix for overflow issue in taxonomy picker +- [#306](https://github.com/estruyf/vscode-front-matter/issues/306): Fix for default value of content type fields ## [7.0.0] - 2022-03-21 - [Release notes](https://beta.frontmatter.codes/updates/v7.0.0) diff --git a/package.json b/package.json index 9cd08d09..d9e2bebe 100644 --- a/package.json +++ b/package.json @@ -748,7 +748,7 @@ "description": "Title to show in the UI" }, "default": { - "type": "string", + "type": ["string", "number", "boolean", "array", "object", "null"], "description": "Default value" }, "choices": { diff --git a/src/helpers/ContentType.ts b/src/helpers/ContentType.ts index fa32b064..db032352 100644 --- a/src/helpers/ContentType.ts +++ b/src/helpers/ContentType.ts @@ -152,8 +152,14 @@ export class ContentType { if (field.type === "fields") { data[field.name] = this.processFields(field, titleValue, {}); } else { - data[field.name] = field.default ? processKnownPlaceholders(field.default, titleValue, dateFormat) : ""; - data[field.name] = field.default ? ArticleHelper.processCustomPlaceholders(data[field.name], titleValue) : ""; + const defaultValue = field.default; + + if (typeof defaultValue === "string") { + data[field.name] = processKnownPlaceholders(defaultValue, titleValue, dateFormat); + data[field.name] = ArticleHelper.processCustomPlaceholders(data[field.name], titleValue); + } else { + data[field.name] = typeof defaultValue !== "undefined" ? defaultValue : ""; + } } } }