Skip to content

Commit

Permalink
refactor: ♻️ Simplify index note filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Nov 25, 2021
1 parent a7ccf78 commit 4fb11fc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
20 changes: 13 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26426,7 +26426,7 @@ class BCSettingTab extends require$$0.PluginSettingTab {
await plugin.saveSettings();
});
new require$$0.Setting(trailDetails)
.setName("Index/Home Note(s)")
.setName("Index Note(s)")
.setDesc("The note that all of your other notes lead back to. The parent of all your parent notes. Just enter the name. So if your index note is `000 Home.md`, enter `000 Home`. You can also have multiple index notes (comma-separated list). The breadcrumb trail will show the shortest path back to any one of the index notes listed. You can now leave this field empty, meaning the trail will show a path going as far up the parent-tree as possible.")
.addText((text) => {
text
Expand Down Expand Up @@ -50547,7 +50547,12 @@ class BCPlugin extends require$$0.Plugin {
console.time("Link-Notes");
this.addLinkNotesToGraph(eligableAlts["BC-link-note"], frontms, mainG);
console.timeEnd("Link-Notes");
this.addTraverseNotesToGraph(eligableAlts["BC-traverse-note"], frontms, mainG, this.buildObsGraph());
// this.addTraverseNotesToGraph(
// eligableAlts["BC-traverse-note"],
// frontms,
// mainG,
// this.buildObsGraph()
// );
files.forEach((file) => {
const { basename } = file;
addNodesIfNot(mainG, [basename]);
Expand Down Expand Up @@ -50669,18 +50674,19 @@ class BCPlugin extends require$$0.Plugin {
return null;
const allTrails = this.bfsAllPaths(g, basename);
let filteredTrails = [...allTrails];
const { indexNotes } = this.settings;
const { indexNotes, showAllPathsIfNoneToIndexNote } = this.settings;
// Filter for index notes
if (indexNotes[0] !== "" && filteredTrails[0].length > 0) {
if (
// Works for `undefined` and `""`
indexNotes[0] &&
filteredTrails.length) {
filteredTrails = filteredTrails.filter((trail) => indexNotes.includes(trail[0]));
if (filteredTrails.length === 0 &&
this.settings.showAllPathsIfNoneToIndexNote)
if (filteredTrails.length === 0 && showAllPathsIfNoneToIndexNote)
filteredTrails = [...allTrails];
}
const sortedTrails = filteredTrails
.filter((trail) => trail.length > 0)
.sort((a, b) => a.length - b.length);
loglevel.info({ sortedTrails });
return sortedTrails;
}
getLimitedTrailSub() {
Expand Down
2 changes: 1 addition & 1 deletion src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ export class BCSettingTab extends PluginSettingTab {
});

new Setting(trailDetails)
.setName("Index/Home Note(s)")
.setName("Index Note(s)")
.setDesc(
"The note that all of your other notes lead back to. The parent of all your parent notes. Just enter the name. So if your index note is `000 Home.md`, enter `000 Home`. You can also have multiple index notes (comma-separated list). The breadcrumb trail will show the shortest path back to any one of the index notes listed. You can now leave this field empty, meaning the trail will show a path going as far up the parent-tree as possible."
)
Expand Down
28 changes: 14 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1074,12 +1074,12 @@ export default class BCPlugin extends Plugin {
console.time("Link-Notes");
this.addLinkNotesToGraph(eligableAlts["BC-link-note"], frontms, mainG);
console.timeEnd("Link-Notes");
this.addTraverseNotesToGraph(
eligableAlts["BC-traverse-note"],
frontms,
mainG,
this.buildObsGraph()
);
// this.addTraverseNotesToGraph(
// eligableAlts["BC-traverse-note"],
// frontms,
// mainG,
// this.buildObsGraph()
// );

files.forEach((file) => {
const { basename } = file;
Expand Down Expand Up @@ -1229,27 +1229,27 @@ export default class BCPlugin extends Plugin {
const { basename, extension } = currFile;
if (extension !== "md") return null;

const allTrails: string[][] = this.bfsAllPaths(g, basename);
const allTrails = this.bfsAllPaths(g, basename);
let filteredTrails = [...allTrails];

const { indexNotes } = this.settings;
const { indexNotes, showAllPathsIfNoneToIndexNote } = this.settings;
// Filter for index notes
if (indexNotes[0] !== "" && filteredTrails[0].length > 0) {
if (
// Works for `undefined` and `""`
indexNotes[0] &&
filteredTrails.length
) {
filteredTrails = filteredTrails.filter((trail) =>
indexNotes.includes(trail[0])
);
if (
filteredTrails.length === 0 &&
this.settings.showAllPathsIfNoneToIndexNote
)
if (filteredTrails.length === 0 && showAllPathsIfNoneToIndexNote)
filteredTrails = [...allTrails];
}

const sortedTrails = filteredTrails
.filter((trail) => trail.length > 0)
.sort((a, b) => a.length - b.length);

info({ sortedTrails });
return sortedTrails;
}

Expand Down

0 comments on commit 4fb11fc

Please sign in to comment.