Skip to content

Commit

Permalink
fix(TagNote): 🐛 Add allTags differently
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jan 8, 2022
1 parent bf86283 commit 38b8569
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
24 changes: 13 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
};
Expand Down
27 changes: 14 additions & 13 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import type {
import MatrixView from "./MatrixView";
import {
createOrUpdateYaml,
dropHash,
dropWikilinks,
fallbackOppField,
getBaseFromMDPath,
Expand Down Expand Up @@ -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(
Expand All @@ -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));
};
Expand Down
3 changes: 3 additions & 0 deletions src/sharedFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,6 @@ export function strToRegex(input: string) {
return null;
}
}

export const dropHash = (tag: string) =>
tag.startsWith("#") ? tag.slice(1) : tag;

0 comments on commit 38b8569

Please sign in to comment.