fix: allowing multiple tags in title and frontmatter when overwrite is true

This commit is contained in:
Baptiste Zorzi 2026-05-26 18:16:30 +02:00
parent edb47272cc
commit 08970c84b2
2 changed files with 39 additions and 36 deletions

View file

@ -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 = "";

View file

@ -69,8 +69,8 @@ export class ViewManager {
return tags;
}
async insertAtFrontMatter(key: string, value: string, overwrite = false, prefix = '', suffix = ''): Promise<void> {
value = `${prefix}${value}${suffix}`;
async insertAtFrontMatter(key: string, values: string[], overwrite = false, prefix = '', suffix = ''): Promise<void> {
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<void> {
value = `${prefix}${value}${suffix}`;
async insertAtTitle(values: string[], overwrite = false, prefix = '', suffix = ''): Promise<void> {
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
}
}
}