diff --git a/package.json b/package.json index a4400991..2f06a90a 100644 --- a/package.json +++ b/package.json @@ -130,7 +130,7 @@ "boolean", "choice" ], - "description": "" + "description": "Type of the draft field you want to use" }, "name": { "type": "string", @@ -709,6 +709,20 @@ "default": "yyyy-MM-dd", "markdownDescription": "Specify the prefix you want to add for your new article filenames. [Check in the docs](https://frontmatter.codes/docs/settings#frontmatter.templates.prefix)", "scope": "Templates" + }, + "frontMatter.global.notifications": { + "type": "array", + "items": { + "type": "string", + "enum": [ + "info", + "warning", + "error" + ] + }, + "default": ["info", "warning", "error"], + "markdownDescription": "Specifies the notifications you want to see. By default, all notifications types will be shown. [Check in the docs](https://frontmatter.codes/docs/settings#frontMatter.global.notifications)", + "scope": "Templates" } } }, diff --git a/src/constants/settings.ts b/src/constants/settings.ts index 528f4d11..52909c0a 100644 --- a/src/constants/settings.ts +++ b/src/constants/settings.ts @@ -2,6 +2,8 @@ export const EXTENSION_NAME = "Front Matter"; export const CONFIG_KEY = "frontMatter"; +export const SETTING_GLOBAL_NOTIFICATIONS = "global.notifications"; + export const SETTING_TAXONOMY_TAGS = "taxonomy.tags"; export const SETTING_TAXONOMY_CATEGORIES = "taxonomy.categories"; export const SETTING_TAXONOMY_CUSTOM = "taxonomy.customTaxonomy"; diff --git a/src/helpers/ArticleHelper.ts b/src/helpers/ArticleHelper.ts index f6bc03db..6a4057cd 100644 --- a/src/helpers/ArticleHelper.ts +++ b/src/helpers/ArticleHelper.ts @@ -17,6 +17,7 @@ import { ContentType } from '../models'; import { DateHelper } from './DateHelper'; export class ArticleHelper { + private static notifiedFiles: string[] = []; /** * Get the contents of the current article @@ -246,6 +247,8 @@ export class ArticleHelper { } } + this.notifiedFiles = this.notifiedFiles.filter(n => n !== fileName); + return article; } } @@ -258,14 +261,18 @@ export class ArticleHelper { }]; if (!surpressNotification) { - Notifications.error(`There seems to be an issue parsing the content its front matter. FileName: ${basename(fileName)}. ERROR: ${error.message || error}`, ...items).then((result: any) => { - if (result?.title) { - const item = items.find(i => i.title === result.title); - if (item) { - item.action(); + if (this.notifiedFiles.indexOf(fileName) === -1) { + Notifications.error(`There seems to be an issue parsing the content its front matter. FileName: ${basename(fileName)}. ERROR: ${error.message || error}`, ...items).then((result: any) => { + if (result?.title) { + const item = items.find(i => i.title === result.title); + if (item) { + item.action(); + } } - } - }); + }); + + this.notifiedFiles.push(fileName); + } } } return null; diff --git a/src/helpers/Notifications.ts b/src/helpers/Notifications.ts index 0f4b110f..b3adff91 100644 --- a/src/helpers/Notifications.ts +++ b/src/helpers/Notifications.ts @@ -1,22 +1,52 @@ import { window } from "vscode"; -import { Logger } from "."; -import { EXTENSION_NAME } from "../constants"; +import { EXTENSION_NAME, SETTING_GLOBAL_NOTIFICATIONS } from "../constants"; +import { Logger } from "./Logger"; +import { Settings } from "./SettingsHelper"; export class Notifications { - public static info(message: string, items?: any): Thenable { + public static info(message: string, items?: any): Thenable { Logger.info(`${EXTENSION_NAME}: ${message}`, "INFO"); - return window.showInformationMessage(`${EXTENSION_NAME}: ${message}`, items); + + if (this.shouldShow("INFO")) { + return window.showInformationMessage(`${EXTENSION_NAME}: ${message}`, items); + } + + return Promise.resolve(undefined); } - public static warning(message: string, items?: any): Thenable { + public static warning(message: string, items?: any): Thenable { Logger.info(`${EXTENSION_NAME}: ${message}`, "WARNING"); - return window.showWarningMessage(`${EXTENSION_NAME}: ${message}`, items); + + if (this.shouldShow("WARNING")) { + return window.showWarningMessage(`${EXTENSION_NAME}: ${message}`, items); + } + + return Promise.resolve(undefined); } - public static error(message: string, items?: any): Thenable { + public static error(message: string, items?: any): Thenable { Logger.info(`${EXTENSION_NAME}: ${message}`, "ERROR"); - return window.showErrorMessage(`${EXTENSION_NAME}: ${message}`, items); + + if (this.shouldShow("ERROR")) { + return window.showErrorMessage(`${EXTENSION_NAME}: ${message}`, items); + } + + return Promise.resolve(undefined); + } + + private static shouldShow(level: "INFO" | "WARNING" | "ERROR"): boolean { + let levels = Settings.get(SETTING_GLOBAL_NOTIFICATIONS); + + if (!levels) { + return true; + } + + if (levels.map(l => l.toLowerCase()).includes(level.toLowerCase())) { + return true; + } + + return false; } } \ No newline at end of file