From ab3a2a562f8da3da5a66966d60f7c68631af3b57 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Sat, 26 Jun 2021 14:14:33 +0200 Subject: [PATCH] fix: breacrumb trail with multiple parent fields --- src/main.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index 2aa47a5f..ab61c32f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -139,8 +139,14 @@ export default class BreadcrumbsPlugin extends Plugin { getParentObjArr(fileFrontmatterArr: fileFrontmatter[]): ParentObj[] { const settings = this.settings; + const parentFields = settings.parentFieldName + .split(",") + .map((str) => str.trim()); + return fileFrontmatterArr.map((fileFrontmatter) => { - const parents = this.getFields(fileFrontmatter, settings.parentFieldName); + const parents: string[] = parentFields + .map((parentField) => this.getFields(fileFrontmatter, parentField)) + .flat(); return { current: fileFrontmatter.file, parents }; }); @@ -178,8 +184,16 @@ export default class BreadcrumbsPlugin extends Plugin { let step = userTo; const breadcrumbs: string[] = []; - // Check if a path even exists - if (paths[step].distance === Infinity) { + // Check if indexNote exists + if ( + !this.app.metadataCache.getFirstLinkpathDest( + userTo, + this.app.workspace.getActiveFile().path + ) + ) { + return [`${userTo} is not a note in your vault`]; + } else if (paths[step].distance === Infinity) { + // Check if a path even exists return [`No path to ${userTo} was found from the current note`]; } else { // If it does, walk it until arriving at `from`