Skip to content

Commit

Permalink
fix: breacrumb trail with multiple parent fields
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jun 26, 2021
1 parent 291e31c commit ab3a2a5
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
});
Expand Down Expand Up @@ -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`
Expand Down

0 comments on commit ab3a2a5

Please sign in to comment.