Skip to content

Commit

Permalink
feat(DendronNote): ✨ Allow stubs (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jan 29, 2022
1 parent 0a76c41 commit f976162
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 39 deletions.
61 changes: 46 additions & 15 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31591,30 +31591,61 @@ function addCSVCrumbs(g, CSVRows, dir, field) {
});
}

const getDendronParent = (dendron, splitter) => dendron.split(splitter).slice(0, -1).join(splitter);
function addDendronNotesToGraph(plugin, frontms, mainG) {
const { settings } = plugin;
const { addDendronNotes, dendronNoteDelimiter, dendronNoteField } = settings;
if (!addDendronNotes)
return;
for (const frontm of frontms) {
// Doesn't currently work yet
if (frontm[BC_IGNORE_DENDRON])
continue;
const basename = getDVBasename(frontm.file);
const splits = basename.split(dendronNoteDelimiter);
if (splits.length <= 1)
continue;
const nextSlice = splits.slice(0, -1).join(dendronNoteDelimiter);
if (!nextSlice)
continue;
const nextSliceFile = frontms.find((fm) => getDVBasename(fm.file) === nextSlice);
if (!nextSliceFile || nextSliceFile[BC_IGNORE_DENDRON])
continue;
const sourceOrder = getSourceOrder(frontm);
const targetOrder = getTargetOrder(frontms, nextSlice);
populateMain(settings, mainG, basename, dendronNoteField, nextSlice, sourceOrder, targetOrder, true);
let curr = getDVBasename(frontm.file);
let parent = getDendronParent(curr, dendronNoteDelimiter);
while (parent !== "") {
const parentFile = frontms.find((fm) => getDVBasename(fm.file) === parent);
// !parentFile implies a "stub"
if (!parentFile || parentFile[BC_IGNORE_DENDRON] !== true) {
populateMain(settings, mainG, curr, dendronNoteField, parent, 9999, 9999, true);
}
curr = parent;
parent = getDendronParent(parent, dendronNoteDelimiter);
}
}
}
}
// export function addDendronNotesToGraph(
// plugin: BCPlugin,
// frontms: dvFrontmatterCache[],
// mainG: MultiGraph
// ) {
// const { settings } = plugin;
// const { addDendronNotes, dendronNoteDelimiter, dendronNoteField } = settings;
// if (!addDendronNotes) return;
// for (const frontm of frontms) {
// if (frontm[BC_IGNORE_DENDRON]) continue;
// const basename = getDVBasename(frontm.file);
// const splits = basename.split(dendronNoteDelimiter);
// if (splits.length <= 1) continue;
// const nextSlice = splits.slice(0, -1).join(dendronNoteDelimiter);
// if (!nextSlice) continue;
// const nextSliceFile = frontms.find(
// (fm) => getDVBasename(fm.file) === nextSlice
// );
// if (!nextSliceFile || nextSliceFile[BC_IGNORE_DENDRON]) continue;
// const sourceOrder = getSourceOrder(frontm);
// const targetOrder = getTargetOrder(frontms, nextSlice);
// populateMain(
// settings,
// mainG,
// basename,
// dendronNoteField,
// nextSlice,
// sourceOrder,
// targetOrder,
// true
// );
// }
// }

const getSubsFromFolder = (folder) => {
const otherNotes = [], subFolders = [];
Expand Down
89 changes: 65 additions & 24 deletions src/AlternativeHierarchies/DendronNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
} from "../Utils/graphUtils";
import { getDVBasename } from "../Utils/ObsidianUtils";

const getDendronParent = (dendron: string, splitter: string) =>
dendron.split(splitter).slice(0, -1).join(splitter);

export function addDendronNotesToGraph(
plugin: BCPlugin,
frontms: dvFrontmatterCache[],
Expand All @@ -19,34 +22,72 @@ export function addDendronNotesToGraph(
if (!addDendronNotes) return;

for (const frontm of frontms) {
// Doesn't currently work yet
if (frontm[BC_IGNORE_DENDRON]) continue;

const basename = getDVBasename(frontm.file);
let curr = getDVBasename(frontm.file);
let parent = getDendronParent(curr, dendronNoteDelimiter);

const splits = basename.split(dendronNoteDelimiter);
if (splits.length <= 1) continue;
while (parent !== "") {
const parentFile = frontms.find(
(fm) => getDVBasename(fm.file) === parent
);

const nextSlice = splits.slice(0, -1).join(dendronNoteDelimiter);
if (!nextSlice) continue;
const nextSliceFile = frontms.find(
(fm) => getDVBasename(fm.file) === nextSlice
);
// !parentFile implies a "stub"
if (!parentFile || parentFile[BC_IGNORE_DENDRON] !== true) {
populateMain(
settings,
mainG,
curr,
dendronNoteField,
parent,
9999,
9999,
true
);
}
curr = parent;
parent = getDendronParent(parent, dendronNoteDelimiter);
}
}
}

if (!nextSliceFile || nextSliceFile[BC_IGNORE_DENDRON]) continue;
// export function addDendronNotesToGraph(
// plugin: BCPlugin,
// frontms: dvFrontmatterCache[],
// mainG: MultiGraph
// ) {
// const { settings } = plugin;
// const { addDendronNotes, dendronNoteDelimiter, dendronNoteField } = settings;
// if (!addDendronNotes) return;

const sourceOrder = getSourceOrder(frontm);
const targetOrder = getTargetOrder(frontms, nextSlice);
// for (const frontm of frontms) {
// if (frontm[BC_IGNORE_DENDRON]) continue;

populateMain(
settings,
mainG,
basename,
dendronNoteField,
nextSlice,
sourceOrder,
targetOrder,
true
);
}
}
// const basename = getDVBasename(frontm.file);

// const splits = basename.split(dendronNoteDelimiter);
// if (splits.length <= 1) continue;

// const nextSlice = splits.slice(0, -1).join(dendronNoteDelimiter);
// if (!nextSlice) continue;
// const nextSliceFile = frontms.find(
// (fm) => getDVBasename(fm.file) === nextSlice
// );

// if (!nextSliceFile || nextSliceFile[BC_IGNORE_DENDRON]) continue;

// const sourceOrder = getSourceOrder(frontm);
// const targetOrder = getTargetOrder(frontms, nextSlice);

// populateMain(
// settings,
// mainG,
// basename,
// dendronNoteField,
// nextSlice,
// sourceOrder,
// targetOrder,
// true
// );
// }
// }

0 comments on commit f976162

Please sign in to comment.