diff --git a/CHANGELOG.md b/CHANGELOG.md index aa96f6a4..fa2da421 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,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/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); 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`)) { 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)) {