From b54eb5a3603a7df222467e09706326a4e4c2da27 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 14 Nov 2022 10:40:30 +0100 Subject: [PATCH 1/3] #462 - Fix issue in script error notification --- CHANGELOG.md | 1 + src/helpers/CustomScript.ts | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f3f64fc..b5463654 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - Fix field error message color - [#433](https://github.com/estruyf/vscode-front-matter/issues/433): Fix issue with rendering an incorrect title value on the content dashboard +- [#462](https://github.com/estruyf/vscode-front-matter/issues/462): Fix issue in script error notification ## [8.1.2] - 2022-10-06 diff --git a/src/helpers/CustomScript.ts b/src/helpers/CustomScript.ts index 95525db5..e80c893c 100644 --- a/src/helpers/CustomScript.ts +++ b/src/helpers/CustomScript.ts @@ -195,7 +195,11 @@ export class CustomScript { const output = await CustomScript.executeScript(script, wsPath, `"${wsPath}" "${contentPath}" ${articleData}`); return output; } catch (e) { - Notifications.error(`${script.title}: ${(e as Error).message}`); + if (typeof e === "string") { + Notifications.error(`${script.title}: ${e}`); + } else { + Notifications.error(`${script.title}: ${(e as Error).message}`); + } return null; } } @@ -285,6 +289,7 @@ export class CustomScript { exec(fullScript, (error, stdout) => { if (error) { reject(error.message); + return; } if (stdout && stdout.endsWith(`\n`)) { From 0ea06a841eefa623c88e1668329d715f886c51f3 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 14 Nov 2022 10:40:52 +0100 Subject: [PATCH 2/3] #412 - script splitting fix --- src/helpers/SettingsHelper.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/helpers/SettingsHelper.ts b/src/helpers/SettingsHelper.ts index 3aa17869..04e69e03 100644 --- a/src/helpers/SettingsHelper.ts +++ b/src/helpers/SettingsHelper.ts @@ -484,14 +484,8 @@ export class Settings { // Array settings if (Settings.isEqualOrStartsWith(relSettingName, SETTING_CUSTOM_SCRIPTS)) { - // Get the correct setting name - let settingNameValue = "" - if (relSettingName === SETTING_CUSTOM_SCRIPTS.toLowerCase()) { - settingNameValue = SETTING_CUSTOM_SCRIPTS; - } - - const crntValue = Settings.globalConfig[`${CONFIG_KEY}.${settingNameValue}`] || []; - Settings.globalConfig[`${CONFIG_KEY}.${settingNameValue}`] = [...crntValue, configJson]; + const crntValue = Settings.globalConfig[`${CONFIG_KEY}.${SETTING_CUSTOM_SCRIPTS}`] || []; + Settings.globalConfig[`${CONFIG_KEY}.${SETTING_CUSTOM_SCRIPTS}`] = [...crntValue, configJson]; } // Content types else if (Settings.isEqualOrStartsWith(relSettingName, SETTING_TAXONOMY_CONTENT_TYPES)) { From 59cbc03b0ccfea371b08fe8df8b5ebfccd4ad858 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 14 Nov 2022 10:48:15 +0100 Subject: [PATCH 3/3] #458 - Add prefix to page bundles --- src/helpers/ArticleHelper.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/helpers/ArticleHelper.ts b/src/helpers/ArticleHelper.ts index 541e7881..258b285b 100644 --- a/src/helpers/ArticleHelper.ts +++ b/src/helpers/ArticleHelper.ts @@ -338,13 +338,21 @@ export class ArticleHelper { if (typeof filePrefixOnFolder !== "undefined") { prefix = filePrefixOnFolder; } + + if (prefix && typeof prefix === "string") { + prefix = `${format(new Date(), DateHelper.formatUpdate(prefix) as string)}`; + } // Name of the file or folder to create - const sanitizedName = ArticleHelper.sanitize(titleValue); + let sanitizedName = ArticleHelper.sanitize(titleValue); let newFilePath: string | undefined; // Create a folder with the `index.md` file if (contentType?.pageBundle) { + if (prefix && typeof prefix === "string") { + sanitizedName = `${prefix}-${sanitizedName}`; + } + const newFolder = join(folderPath, sanitizedName); if (await existsAsync(newFolder)) { Notifications.error(`A page bundle with the name ${sanitizedName} already exists in ${folderPath}`); @@ -357,7 +365,7 @@ export class ArticleHelper { let newFileName = `${sanitizedName}.${fileExtension || contentType?.fileType || fileType}`; if (prefix && typeof prefix === "string") { - newFileName = `${format(new Date(), DateHelper.formatUpdate(prefix) as string)}-${newFileName}`; + newFileName = `${prefix}-${newFileName}`; } newFilePath = join(folderPath, newFileName);