From 42c44ca3a52237a71955fb2e0194e62cd9c97137 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Thu, 16 Mar 2023 09:51:57 +0100 Subject: [PATCH] #539 - fix file prefix --- CHANGELOG.md | 1 + src/commands/Article.ts | 2 +- src/helpers/ArticleHelper.ts | 12 +++++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33a692dc..b85d4804 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ - [#521](https://github.com/estruyf/vscode-front-matter/issues/521): Fix empty snippets dashboard placeholder - [#526](https://github.com/estruyf/vscode-front-matter/issues/526): Fix card content menu - [#531](https://github.com/estruyf/vscode-front-matter/issues/531): Fix prettier update which caused data views to not render list items +- [#539](https://github.com/estruyf/vscode-front-matter/issues/539): Fix the override of the default file prefix on content creation ## [8.3.0] - 2023-02-14 - [Release notes](https://beta.frontmatter.codes/updates/v8.3.0) diff --git a/src/commands/Article.ts b/src/commands/Article.ts index 2dbc670f..1e36403f 100644 --- a/src/commands/Article.ts +++ b/src/commands/Article.ts @@ -226,7 +226,7 @@ export class Article { let filePrefix = Settings.get(SETTING_TEMPLATES_PREFIX); const contentType = ArticleHelper.getContentType(article.data); - filePrefix = ArticleHelper.getFilePrefix(editor.document.uri.fsPath, contentType); + filePrefix = ArticleHelper.getFilePrefix(filePrefix, editor.document.uri.fsPath, contentType); const titleField = 'title'; const articleTitle: string = article.data[titleField]; diff --git a/src/helpers/ArticleHelper.ts b/src/helpers/ArticleHelper.ts index 46624367..2aad5508 100644 --- a/src/helpers/ArticleHelper.ts +++ b/src/helpers/ArticleHelper.ts @@ -383,7 +383,7 @@ export class ArticleHelper { const fileType = Settings.get(SETTING_CONTENT_DEFAULT_FILETYPE); let prefix = Settings.get(SETTING_TEMPLATES_PREFIX); - prefix = ArticleHelper.getFilePrefix(folderPath, contentType); + prefix = ArticleHelper.getFilePrefix(prefix, folderPath, contentType); // Name of the file or folder to create let sanitizedName = ArticleHelper.sanitize(titleValue); @@ -436,8 +436,14 @@ export class ArticleHelper { * @param contentType * @returns */ - public static getFilePrefix(filePath?: string, contentType?: ContentType): string | undefined { - let prefix = undefined; + public static getFilePrefix( + prefix: string | null | undefined, + filePath?: string, + contentType?: ContentType + ): string | undefined { + if (!prefix) { + prefix = undefined; + } // Retrieve the file prefix from the folder if (filePath) {