From f75653d8f7db264204fb5c96956222ba8acc10b0 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Sat, 15 Jan 2022 20:41:42 +0200 Subject: [PATCH] feat(DendronNote): :sparkles: Add `BC-ignore-dendron: true` to not treat a dendron note as such (Fix #277) --- src/AlternativeHierarchies/DendronNotes.ts | 53 ++++++++++------------ 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/src/AlternativeHierarchies/DendronNotes.ts b/src/AlternativeHierarchies/DendronNotes.ts index 9112c6fb..dc9003e5 100644 --- a/src/AlternativeHierarchies/DendronNotes.ts +++ b/src/AlternativeHierarchies/DendronNotes.ts @@ -17,35 +17,32 @@ export function addDendronNotesToGraph( for (const frontm of frontms) { // Doesn't currently work yet if (frontm[BC_IGNORE_DENDRON]) continue; - const { file } = frontm; - const basename = getDVBasename(file); + + const basename = getDVBasename(frontm.file); const splits = basename.split(dendronNoteDelimiter); - if (splits.length < 2) continue; - - // Probably inefficient to reverse then unreverse it. I can probably just use slice(-i) - const reversed = splits.reverse(); - reversed.forEach((split, i) => { - const currSlice = reversed.slice(i).reverse().join(dendronNoteDelimiter); - const nextSlice = reversed - .slice(i + 1) - .reverse() - .join(dendronNoteDelimiter); - if (!nextSlice) return; - - const sourceOrder = getSourceOrder(frontm); - const targetOrder = getTargetOrder(frontms, nextSlice); - - populateMain( - settings, - mainG, - currSlice, - dendronNoteField, - nextSlice, - sourceOrder, - targetOrder, - true - ); - }); + 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 + ); } }