diff --git a/main.js b/main.js index 903d4850..3da5825f 100644 --- a/main.js +++ b/main.js @@ -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 = []; diff --git a/src/AlternativeHierarchies/DendronNotes.ts b/src/AlternativeHierarchies/DendronNotes.ts index 961fdf7b..e8ab0967 100644 --- a/src/AlternativeHierarchies/DendronNotes.ts +++ b/src/AlternativeHierarchies/DendronNotes.ts @@ -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[], @@ -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 +// ); +// } +// }