Skip to content

Commit

Permalink
feat(TagNote): ✨ BC-tag-note-exact will only include notes with exact…
Browse files Browse the repository at this point in the history
…ly that tag (fix #236)
  • Loading branch information
SkepticMystic committed Jan 3, 2022
1 parent 2ec3e8d commit efd111a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 46 deletions.
42 changes: 21 additions & 21 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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.",
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand All @@ -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.",
Expand Down
39 changes: 14 additions & 25 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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[],
Expand All @@ -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
Expand Down

0 comments on commit efd111a

Please sign in to comment.