Skip to content

Commit

Permalink
fix(TagNote): 🐛 Tags notes are case insensitive, and work with string…
Browse files Browse the repository at this point in the history
…[] or string (fix #219)
  • Loading branch information
SkepticMystic committed Dec 29, 2021
1 parent 8a53195 commit bb92c08
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,16 +935,36 @@ export default class BCPlugin extends Plugin {
const tagNoteFile = altFile.file;

const tagNoteBasename = getDVBasename(tagNoteFile);
const tag = (altFile[BC_TAG_NOTE] as string).trim();
const tag = (altFile[BC_TAG_NOTE] as string).trim().toLowerCase();
if (!tag.startsWith("#")) return;

const hasThisTag = (file: TFile): boolean => {
const cache = this.app.metadataCache.getFileCache(file);
return (
cache?.tags?.map((t) => t.tag).some((t) => t.includes(tag)) ||
cache?.frontmatter?.tags?.includes(tag.slice(1)) ||
cache?.frontmatter?.tag?.includes(tag.slice(1))
);
const { tags, frontmatter } = this.app.metadataCache.getFileCache(file);
if (tags?.map((t) => t.tag.toLowerCase()).some((t) => t.includes(tag)))
return true;

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;
}
};

const targets = frontms
Expand Down

0 comments on commit bb92c08

Please sign in to comment.