diff --git a/main.js b/main.js index 9c4e1377..a523269b 100644 --- a/main.js +++ b/main.js @@ -21017,10 +21017,11 @@ const blankRealNImplied = () => { prev: { reals: [], implieds: [] }, }; }; -const [BC_FOLDER_NOTE, BC_TAG_NOTE, BC_TAG_NOTE_FIELD, BC_LINK_NOTE, BC_TRAVERSE_NOTE, BC_HIDE_TRAIL, BC_ORDER,] = [ +const [BC_FOLDER_NOTE, BC_TAG_NOTE, BC_TAG_NOTE_FIELD, BC_TAG_NOTE_EXACT, BC_LINK_NOTE, BC_TRAVERSE_NOTE, BC_HIDE_TRAIL, BC_ORDER,] = [ "BC-folder-note", "BC-tag-note", "BC-tag-note-field", + "BC-tag-note-exact", "BC-link-note", "BC-traverse-note", "BC-hide-trail", @@ -21045,6 +21046,12 @@ const BC_FIELDS_INFO = [ after: ": ", alt: false, }, + { + field: BC_TAG_NOTE_EXACT, + desc: "Only look for notes with the exact tag. i.e. `#A` won't match `#A/B`", + after: ": true", + alt: false, + }, { field: BC_LINK_NOTE, desc: "Set this note as a Breadcrumbs link-note. All links leaving this note will be added to the graph with the field name specified in this key's value.", @@ -51689,6 +51696,15 @@ class BCPlugin extends require$$0.Plugin { } } }; + this.getAllTags = (file, withHash = true) => { + var _a, _b, _c; + const { tags, frontmatter } = this.app.metadataCache.getFileCache(file); + return [ + ...((_a = tags === null || tags === void 0 ? void 0 : tags.map((t) => t.tag.slice(1))) !== 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) => (withHash ? "#" : "") + t.toLowerCase()); + }; this.getTargetOrder = (frontms, target) => { var _a, _b; return parseInt((_b = (_a = frontms.find((arr) => arr.file.basename === target)) === null || _a === void 0 ? void 0 : _a[BC_ORDER]) !== null && _b !== void 0 ? _b : "9999"); @@ -52442,26 +52458,10 @@ class BCPlugin extends require$$0.Plugin { if (!tag.startsWith("#")) return; const hasThisTag = (file) => { - var _a, _b; - const { tags, frontmatter } = this.app.metadataCache.getFileCache(file); - if (tags === null || tags === void 0 ? void 0 : tags.map((t) => t.tag.toLowerCase()).some((t) => t.includes(tag))) - return true; - if (typeof (frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.tag) === "string") { - if (frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.tag.toLowerCase().includes(tag.slice(1))) - return true; - } - else { - if ((_a = frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.tag) === null || _a === void 0 ? void 0 : _a.some((t) => t.toLowerCase().includes(tag.slice(1)))) - return true; - } - if (typeof (frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.tags) === "string") { - if (frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.tags.toLowerCase().includes(tag.slice(1))) - return true; - } - else { - if ((_b = frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.tags) === null || _b === void 0 ? void 0 : _b.some((t) => t.toLowerCase().includes(tag.slice(1)))) - return true; - } + const allTags = this.getAllTags(file); + return altFile[BC_TAG_NOTE_EXACT] + ? allTags.includes(tag) + : allTags.some((t) => t.includes(tag)); }; const targets = frontms .map((ff) => ff.file) diff --git a/src/constants.ts b/src/constants.ts index 99daf6ef..57d8a047 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -73,6 +73,7 @@ export const [ BC_FOLDER_NOTE, BC_TAG_NOTE, BC_TAG_NOTE_FIELD, + BC_TAG_NOTE_EXACT, BC_LINK_NOTE, BC_TRAVERSE_NOTE, BC_HIDE_TRAIL, @@ -81,6 +82,7 @@ export const [ "BC-folder-note", "BC-tag-note", "BC-tag-note-field", + "BC-tag-note-exact", "BC-link-note", "BC-traverse-note", "BC-hide-trail", @@ -106,6 +108,12 @@ export const BC_FIELDS_INFO = [ after: ": ", alt: false, }, + { + field: BC_TAG_NOTE_EXACT, + desc: "Only look for notes with the exact tag. i.e. `#A` won't match `#A/B`", + after: ": true", + alt: false, + }, { field: BC_LINK_NOTE, desc: "Set this note as a Breadcrumbs link-note. All links leaving this note will be added to the graph with the field name specified in this key's value.", diff --git a/src/main.ts b/src/main.ts index c3930570..80e9d7ff 100644 --- a/src/main.ts +++ b/src/main.ts @@ -34,6 +34,7 @@ import { BC_LINK_NOTE, BC_ORDER, BC_TAG_NOTE, + BC_TAG_NOTE_EXACT, BC_TAG_NOTE_FIELD, BC_TRAVERSE_NOTE, DEFAULT_SETTINGS, @@ -1061,6 +1062,15 @@ export default class BCPlugin extends Plugin { }); } + getAllTags = (file: TFile, withHash = true): string[] => { + const { tags, frontmatter } = this.app.metadataCache.getFileCache(file); + return [ + ...(tags?.map((t) => t.tag.slice(1)) ?? []), + ...[...(frontmatter?.tags ?? [])].flat(), + ...[...(frontmatter?.tag ?? [])].flat(), + ].map((t: string) => (withHash ? "#" : "") + t.toLowerCase()); + }; + addTagNotesToGraph( eligableAlts: dvFrontmatterCache[], frontms: dvFrontmatterCache[], @@ -1076,32 +1086,11 @@ export default class BCPlugin extends Plugin { if (!tag.startsWith("#")) return; const hasThisTag = (file: TFile): boolean => { - const { tags, frontmatter } = this.app.metadataCache.getFileCache(file); - if (tags?.map((t) => t.tag.toLowerCase()).some((t) => t.includes(tag))) - return true; + const allTags = this.getAllTags(file); - if (typeof frontmatter?.tag === "string") { - if (frontmatter?.tag.toLowerCase().includes(tag.slice(1))) - return true; - } else { - if ( - (frontmatter?.tag as string[])?.some((t) => - t.toLowerCase().includes(tag.slice(1)) - ) - ) - return true; - } - if (typeof frontmatter?.tags === "string") { - if (frontmatter?.tags.toLowerCase().includes(tag.slice(1))) - return true; - } else { - if ( - (frontmatter?.tags as string[])?.some((t) => - t.toLowerCase().includes(tag.slice(1)) - ) - ) - return true; - } + return altFile[BC_TAG_NOTE_EXACT] + ? allTags.includes(tag) + : allTags.some((t) => t.includes(tag)); }; const targets = frontms