From ecc9c740919b3af103d2783ca4afe642e8caab03 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Wed, 10 Aug 2022 16:09:21 +0200 Subject: [PATCH 1/3] #384: Fix issue `title` field in sub-fields --- CHANGELOG.md | 1 + src/dashboardWebView/index.tsx | 5 ++++- src/helpers/ContentType.ts | 8 +++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5aafdf97..92da6383 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ ### 🐞 Fixes - [#378](https://github.com/estruyf/vscode-front-matter/issues/378): Fix last modified update only to content in content folders +- [#384](https://github.com/estruyf/vscode-front-matter/issues/384): Fix issue `title` field in sub-fields ## [8.0.1] - 2022-07-13 diff --git a/src/dashboardWebView/index.tsx b/src/dashboardWebView/index.tsx index cd648392..fdd64f11 100644 --- a/src/dashboardWebView/index.tsx +++ b/src/dashboardWebView/index.tsx @@ -40,7 +40,10 @@ if (elm) { tracesSampleRate: 0, // No performance tracing required release: version || "", environment: environment || "", - ignoreErrors: ['ResizeObserver loop limit exceeded'] + ignoreErrors: [ + 'ResizeObserver loop limit exceeded', + "Cannot read properties of undefined (reading 'unobserve')" + ] }); } diff --git a/src/helpers/ContentType.ts b/src/helpers/ContentType.ts index f1b3cf1d..a407887c 100644 --- a/src/helpers/ContentType.ts +++ b/src/helpers/ContentType.ts @@ -572,7 +572,7 @@ export class ContentType { * @param contentType * @param data */ - private static async processFields(obj: IContentType | Field, titleValue: string, data: any, filePath: string) { + private static async processFields(obj: IContentType | Field, titleValue: string, data: any, filePath: string, isRoot: boolean = true): Promise { if (obj.fields) { const dateFormat = Settings.get(SETTING_DATE_FORMAT) as string; @@ -581,12 +581,14 @@ export class ContentType { if (field.default) { data[field.name] = processKnownPlaceholders(field.default, titleValue, dateFormat); data[field.name] = await ArticleHelper.processCustomPlaceholders(data[field.name], titleValue, filePath); - } else { + } else if (isRoot) { data[field.name] = titleValue; + } else { + data[field.name] = "" } } else { if (field.type === "fields") { - data[field.name] = await this.processFields(field, titleValue, {}, filePath); + data[field.name] = await this.processFields(field, titleValue, {}, filePath, false); } else { const defaultValue = field.default; From 4a8bbaf82e4ab5a7bc980dc963d2d06a90e61140 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Thu, 11 Aug 2022 17:43:07 +0200 Subject: [PATCH 2/3] Fix for empty tags --- src/dashboardWebView/components/Contents/Item.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/dashboardWebView/components/Contents/Item.tsx b/src/dashboardWebView/components/Contents/Item.tsx index 0991241d..4c2314f9 100644 --- a/src/dashboardWebView/components/Contents/Item.tsx +++ b/src/dashboardWebView/components/Contents/Item.tsx @@ -89,11 +89,13 @@ export const Item: React.FunctionComponent = ({ fmFilePath, date, ti
{ tags.map((tag, index) => ( - - #{tag} - + tag && ( + + #{tag} + + ) )) }
From 1766c19133428f313774e8f795f15049dd8f2d3c Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Thu, 11 Aug 2022 17:52:36 +0200 Subject: [PATCH 3/3] #385: Add a default draft field value --- CHANGELOG.md | 1 + src/helpers/ContentType.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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] = ""; + } } } }