diff --git a/main.js b/main.js index 1d2244bd..69dcc4cd 100644 --- a/main.js +++ b/main.js @@ -22643,7 +22643,8 @@ function strToRegex(input) { console.log(e); return null; } -} +} +const dropHash = (tag) => tag.startsWith("#") ? tag.slice(1) : tag; /* node_modules\svelte-icons\components\IconBase.svelte generated by Svelte v3.35.0 */ @@ -51826,16 +51827,17 @@ class BCPlugin extends require$$0.Plugin { } }; this.getAllTags = (file, withHash = true) => { - var _a, _b, _c; - // const test = getAllTags( - // this.app.metadataCache.getFileCache(this.app.workspace.getActiveFile()) - // ); + var _a, _b; const { tags, frontmatter } = this.app.metadataCache.getFileCache(file); - return [ - ...((_a = tags === null || tags === void 0 ? void 0 : tags.map((t) => (t.tag.startsWith("#") ? t.tag.slice(1) : t.tag))) !== null && _a !== void 0 ? _a : []), - ...[...((_b = frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.tags) !== null && _b !== void 0 ? _b : [])].flat(), - ...[...((_c = frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.tag) !== null && _c !== void 0 ? _c : [])].flat(), - ].map((t) => (!t.startsWith("#") && withHash ? "#" : "") + t.toLowerCase()); + const allTags = []; + tags === null || tags === void 0 ? void 0 : tags.forEach((t) => allTags.push(dropHash(t.tag))); + [(_a = frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.tags) !== null && _a !== void 0 ? _a : []] + .flat() + .forEach((t) => allTags.push(dropHash(t))); + [(_b = frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.tag) !== null && _b !== void 0 ? _b : []] + .flat() + .forEach((t) => allTags.push(dropHash(t))); + return allTags.map((t) => (withHash ? "#" : "") + t.toLowerCase()); }; this.getTargetOrder = (frontms, target) => { var _a, _b; @@ -52597,7 +52599,7 @@ class BCPlugin extends require$$0.Plugin { return; const hasThisTag = (file) => { const allTags = this.getAllTags(file); - return altFile[BC_TAG_NOTE_EXACT] + return altFile[BC_TAG_NOTE_EXACT] !== undefined ? allTags.includes(tag) : allTags.some((t) => t.includes(tag)); }; diff --git a/src/main.ts b/src/main.ts index 7cbe24bd..1d9a9ede 100644 --- a/src/main.ts +++ b/src/main.ts @@ -82,6 +82,7 @@ import type { import MatrixView from "./MatrixView"; import { createOrUpdateYaml, + dropHash, dropWikilinks, fallbackOppField, getBaseFromMDPath, @@ -1078,19 +1079,19 @@ export default class BCPlugin extends Plugin { } getAllTags = (file: TFile, withHash = true): string[] => { - // const test = getAllTags( - // this.app.metadataCache.getFileCache(this.app.workspace.getActiveFile()) - // ); const { tags, frontmatter } = this.app.metadataCache.getFileCache(file); - return [ - ...(tags?.map((t) => (t.tag.startsWith("#") ? t.tag.slice(1) : t.tag)) ?? - []), - ...[...(frontmatter?.tags ?? [])].flat(), - ...[...(frontmatter?.tag ?? [])].flat(), - ].map( - (t: string) => - (!t.startsWith("#") && withHash ? "#" : "") + t.toLowerCase() - ); + const allTags: string[] = []; + + tags?.forEach((t) => allTags.push(dropHash(t.tag))); + + [frontmatter?.tags ?? []] + .flat() + .forEach((t: string) => allTags.push(dropHash(t))); + [frontmatter?.tag ?? []] + .flat() + .forEach((t: string) => allTags.push(dropHash(t))); + + return allTags.map((t) => (withHash ? "#" : "") + t.toLowerCase()); }; addTagNotesToGraph( @@ -1109,7 +1110,7 @@ export default class BCPlugin extends Plugin { const hasThisTag = (file: TFile): boolean => { const allTags = this.getAllTags(file); - return altFile[BC_TAG_NOTE_EXACT] + return altFile[BC_TAG_NOTE_EXACT] !== undefined ? allTags.includes(tag) : allTags.some((t) => t.includes(tag)); }; diff --git a/src/sharedFunctions.ts b/src/sharedFunctions.ts index b4748534..c14a30c4 100644 --- a/src/sharedFunctions.ts +++ b/src/sharedFunctions.ts @@ -319,3 +319,6 @@ export function strToRegex(input: string) { return null; } } + +export const dropHash = (tag: string) => + tag.startsWith("#") ? tag.slice(1) : tag;