From 08970c84b2c4e8146f5d2d92fccaaeca594e46ec Mon Sep 17 00:00:00 2001 From: Baptiste Zorzi Date: Tue, 26 May 2026 18:16:30 +0200 Subject: [PATCH] fix: allowing multiple tags in title and frontmatter when overwrite is true --- src/main.ts | 54 +++++++++++++++++++++++---------------------- src/view-manager.ts | 21 +++++++++--------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/main.ts b/src/main.ts index 8e37a6d..9dd1f6b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -230,12 +230,12 @@ export default class AutoClassifierPlugin extends Plugin { } // ------- [Add Tags] ------- - for (const resOutput of limitedOutputs) { - // Output Type 1. [Tag Case] + Output Type 2. [Wikilink Case] - if ( - commandOption.outType == OutType.Tag || - commandOption.outType == OutType.Wikilink - ) { + // Output Type 1. [Tag Case] + Output Type 2. [Wikilink Case] + if ( + commandOption.outType == OutType.Tag || + commandOption.outType == OutType.Wikilink + ) { + for (const resOutput of limitedOutputs) { if (commandOption.outLocation == OutLocation.Cursor) { this.viewManager.insertAtCursor( resOutput, @@ -244,7 +244,9 @@ export default class AutoClassifierPlugin extends Plugin { commandOption.outPrefix, commandOption.outSuffix, ); - } else if (commandOption.outLocation == OutLocation.ContentTop) { + } else if ( + commandOption.outLocation == OutLocation.ContentTop + ) { this.viewManager.insertAtContentTop( resOutput, commandOption.outType, @@ -253,25 +255,25 @@ export default class AutoClassifierPlugin extends Plugin { ); } } - // Output Type 3. [Frontmatter Case] - else if (commandOption.outType == OutType.FrontMatter) { - this.viewManager.insertAtFrontMatter( - commandOption.key, - resOutput, - commandOption.overwrite, - commandOption.outPrefix, - commandOption.outSuffix, - ); - } - // Output Type 4. [Title] - else if (commandOption.outType == OutType.Title) { - this.viewManager.insertAtTitle( - resOutput, - commandOption.overwrite, - commandOption.outPrefix, - commandOption.outSuffix, - ); - } + } + // Output Type 3. [Frontmatter Case] + else if (commandOption.outType == OutType.FrontMatter) { + this.viewManager.insertAtFrontMatter( + commandOption.key, + limitedOutputs, + commandOption.overwrite, + commandOption.outPrefix, + commandOption.outSuffix, + ); + } + // Output Type 4. [Title] + else if (commandOption.outType == OutType.Title) { + this.viewManager.insertAtTitle( + limitedOutputs, + commandOption.overwrite, + commandOption.outPrefix, + commandOption.outSuffix, + ); } // Show token usage if available let tokenInfo = ""; diff --git a/src/view-manager.ts b/src/view-manager.ts index 20e5a9a..ff73ee7 100644 --- a/src/view-manager.ts +++ b/src/view-manager.ts @@ -69,8 +69,8 @@ export class ViewManager { return tags; } - async insertAtFrontMatter(key: string, value: string, overwrite = false, prefix = '', suffix = ''): Promise { - value = `${prefix}${value}${suffix}`; + async insertAtFrontMatter(key: string, values: string[], overwrite = false, prefix = '', suffix = ''): Promise { + values = values.map((value) => `${prefix}${value}${suffix}`); const activeView = this.app.workspace.getActiveViewOfType(MarkdownView); if (activeView) { @@ -81,27 +81,28 @@ export class ViewManager { if (frontmatter[key] && !overwrite) { // add value as list element if exist if (Array.isArray(frontmatter[key])) { - frontmatter[key].push(value); + for (const value of values) + frontmatter[key].push(value); } else { - frontmatter[key] = [frontmatter[key], value]; + frontmatter[key] = [frontmatter[key], ...values]; } } else { // overwrite - frontmatter[key] = value; + frontmatter[key] = values; } }); } } - async insertAtTitle(value: string, overwrite = false, prefix = '', suffix = ''): Promise { - value = `${prefix}${value}${suffix}`; + async insertAtTitle(values: string[], overwrite = false, prefix = '', suffix = ''): Promise { + values = values.map((value) => `${prefix}${value}${suffix}`); const file = this.app.workspace.getActiveFile(); if (!file) return; let newName = file.basename; if (overwrite) { - newName = `${value}`; + newName = `${values.join(' ')}`; } else { - newName = `${newName} ${value}`; + newName = `${newName} ${values.join(' ')}`; } newName = newName.replace(/[\"\/<>:\|?\"]/g, ''); // for window file name // @ts-ignore @@ -156,4 +157,4 @@ export class ViewManager { else if (outType == OutType.Wikilink) output = `[[${prefix}${value}${suffix}]]`; return output } -} \ No newline at end of file +}