Skip to content

Commit

Permalink
feat(TagNote): ✨ Tag Notes! Similar to Folder Notes, all notes with t…
Browse files Browse the repository at this point in the history
…he tag you specify link to the chosen note
  • Loading branch information
SkepticMystic committed Nov 23, 2021
1 parent 655853b commit c630b6f
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"CSV Crumbs",
"nextPrev",
"DucksView",
"FolderNote"
"FolderNote",
"TagNote"
]
}
44 changes: 44 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49904,6 +49904,8 @@ class BCPlugin extends obsidian.Plugin {
field = upFields[0];
}
const oppField = (_a = getOppFields(userHiers, field)[0]) !== null && _a !== void 0 ? _a : getFields(userHiers, "down")[0];
if (!oppField)
return;
sources.forEach((source) => {
var _a;
// This is getting the order of the folder note, not the source pointing up to it
Expand All @@ -49914,6 +49916,43 @@ class BCPlugin extends obsidian.Plugin {
}
});
}
addTagLinksToGraph(fileFrontmatterArr, mainG) {
const { userHiers } = this.settings;
fileFrontmatterArr.forEach((fileFront) => {
var _a;
const tagNoteFile = fileFront.file;
if (fileFront["BC-tag-note"]) {
const tagNoteBasename = getDVBasename(tagNoteFile);
const tag = fileFront["BC-tag-note"].trim();
if (!tag.startsWith("#"))
return;
const sources = fileFrontmatterArr
.map((ff) => ff.file)
.filter((file) => {
var _a, _b;
return file.path !== tagNoteFile.path &&
((_b = (_a = this.app.metadataCache
.getFileCache(file)) === null || _a === void 0 ? void 0 : _a.tags) === null || _b === void 0 ? void 0 : _b.map((t) => t.tag).some((t) => t.includes(tag)));
})
.map(getDVBasename);
let field = fileFront["BC-tag-note-up"];
const upFields = getFields(userHiers, "up");
if (typeof field !== "string" || !upFields.includes(field)) {
field = upFields[0];
}
const oppField = (_a = getOppFields(userHiers, field)[0]) !== null && _a !== void 0 ? _a : getFields(userHiers, "down")[0];
if (!oppField)
return;
sources.forEach((source) => {
var _a;
// This is getting the order of the folder note, not the source pointing up to it
const sourceOrder = (_a = parseInt(fileFront.order)) !== null && _a !== void 0 ? _a : 9999;
this.populateMain(mainG, source, "up", field, [tagNoteBasename], sourceOrder, fileFrontmatterArr);
this.populateMain(mainG, tagNoteBasename, "down", oppField, [source], sourceOrder, fileFrontmatterArr);
});
}
});
}
async initGraphs() {
const { settings, app } = this;
debugGroupStart(settings, "debugMode", "Initialise Graphs");
Expand Down Expand Up @@ -49967,7 +50006,12 @@ class BCPlugin extends obsidian.Plugin {
this.addHNsToGraph(hierarchyNotesArr, mainG);
// !SECTION Hierarchy Notes
debugGroupEnd(settings, "debugMode");
console.time("Folder-Notes");
this.addFolderNoteLinksToGraph(fileFrontmatterArr, mainG);
console.timeEnd("Folder-Notes");
console.time("Tag-Notes");
this.addTagLinksToGraph(fileFrontmatterArr, mainG);
console.timeEnd("Tag-Notes");
files.forEach((file) => {
const { basename } = file;
addNodesIfNot(mainG, [basename]);
Expand Down
69 changes: 68 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ export default class BCPlugin extends Plugin {
const oppField =
getOppFields(userHiers, field as string)[0] ??
getFields(userHiers, "down")[0];
if (!oppField) return;

sources.forEach((source) => {
// This is getting the order of the folder note, not the source pointing up to it
Expand Down Expand Up @@ -803,6 +804,67 @@ export default class BCPlugin extends Plugin {
});
}

addTagLinksToGraph(
fileFrontmatterArr: dvFrontmatterCache[],
mainG: MultiGraph
) {
const { userHiers } = this.settings;
fileFrontmatterArr.forEach((fileFront) => {
const tagNoteFile = fileFront.file;
if (fileFront["BC-tag-note"]) {
const tagNoteBasename = getDVBasename(tagNoteFile);
const tag = (fileFront["BC-tag-note"] as string).trim();
if (!tag.startsWith("#")) return;

const sources = fileFrontmatterArr
.map((ff) => ff.file)
.filter(
(file) =>
file.path !== tagNoteFile.path &&
this.app.metadataCache
.getFileCache(file)
?.tags?.map((t) => t.tag)
.some((t) => t.includes(tag))
)
.map(getDVBasename);

let field = fileFront["BC-tag-note-up"];
const upFields = getFields(userHiers, "up");
if (typeof field !== "string" || !upFields.includes(field)) {
field = upFields[0];
}

const oppField =
getOppFields(userHiers, field as string)[0] ??
getFields(userHiers, "down")[0];
if (!oppField) return;

sources.forEach((source) => {
// This is getting the order of the folder note, not the source pointing up to it
const sourceOrder = parseInt(fileFront.order) ?? 9999;
this.populateMain(
mainG,
source,
"up",
field as string,
[tagNoteBasename],
sourceOrder,
fileFrontmatterArr
);
this.populateMain(
mainG,
tagNoteBasename,
"down",
oppField,
[source],
sourceOrder,
fileFrontmatterArr
);
});
}
});
}

async initGraphs(): Promise<MultiGraph> {
const { settings, app } = this;
debugGroupStart(settings, "debugMode", "Initialise Graphs");
Expand All @@ -828,7 +890,7 @@ export default class BCPlugin extends Plugin {
const basename = getDVBasename(fileFrontmatter.file);
iterateHiers(userHiers, (hier, dir, field) => {
const values = this.parseFieldValue(fileFrontmatter[field]);
const sourceOrder = parseInt(fileFrontmatter.order) ?? 9999;
const sourceOrder = parseInt(fileFrontmatter.order as string) ?? 9999;
this.populateMain(
mainG,
basename,
Expand Down Expand Up @@ -875,7 +937,12 @@ export default class BCPlugin extends Plugin {

debugGroupEnd(settings, "debugMode");

console.time("Folder-Notes");
this.addFolderNoteLinksToGraph(fileFrontmatterArr, mainG);
console.timeEnd("Folder-Notes");
console.time("Tag-Notes");
this.addTagLinksToGraph(fileFrontmatterArr, mainG);
console.timeEnd("Tag-Notes");

files.forEach((file) => {
const { basename } = file;
Expand Down

0 comments on commit c630b6f

Please sign in to comment.