Skip to content

Commit

Permalink
feat(CreateIndex): ✨ Setting to show aliases in index
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jul 31, 2021
1 parent f46c894 commit 670ae39
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
13 changes: 13 additions & 0 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,19 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
})
);

new Setting(createIndexDetails)
.setName("Show aliases of notes in index")
.setDesc("Show the aliases of each note in brackets. On = yes, off = no.")
.addToggle((toggle) =>
toggle
.setValue(plugin.settings.aliasesInIndex)
.onChange(async (value) => {
console.log(value)
plugin.settings.aliasesInIndex = value;
await plugin.saveSettings();
})
);

const debugDetails: HTMLDetailsElement = containerEl.createEl("details");
debugDetails.createEl("summary", { text: "Debugging" });

Expand Down
39 changes: 22 additions & 17 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ export default class MatrixView extends ItemView {
),
currFile
);
const index = this.createIndex(
currFile + "\n",
allPaths,
currFile,
settings
);
const index = this.createIndex(currFile + "\n", allPaths, settings);
debug(settings, { index });
await navigator.clipboard.writeText(index).then(
() => new Notice("Index copied to clipboard"),
Expand All @@ -63,12 +58,8 @@ export default class MatrixView extends ItemView {
name: "Copy a Global Index to the clipboard",
callback: async () => {
const { gParents, gChildren } = this.plugin.currGraphs;

const terminals = gParents.sinks();
console.log({ terminals });

const settings = this.plugin.settings;
const currFile = this.app.workspace.getActiveFile().basename;

let globalIndex = "";
terminals.forEach((terminal) => {
Expand All @@ -77,12 +68,7 @@ export default class MatrixView extends ItemView {
closeImpliedLinks(gChildren, gParents),
terminal
);
globalIndex = this.createIndex(
globalIndex,
allPaths,
terminal,
settings
);
globalIndex = this.createIndex(globalIndex, allPaths, settings);
});

debug(settings, { globalIndex });
Expand Down Expand Up @@ -194,7 +180,6 @@ export default class MatrixView extends ItemView {
// Gotta give it a starting index. This allows it to work for the global index feat
index: string,
allPaths: string[][],
currFile: string,
settings: BreadcrumbsSettings
): string {
const copy = cloneDeep(allPaths);
Expand All @@ -218,6 +203,26 @@ export default class MatrixView extends ItemView {
index += settings.wikilinkIndex ? "[[" : "";
index += currNode;
index += settings.wikilinkIndex ? "]]" : "";

if (settings.aliasesInIndex) {
const currFile = this.app.metadataCache.getFirstLinkpathDest(
currNode,
this.app.workspace.getActiveFile().path
);
const cache = this.app.metadataCache.getFileCache(currFile);

const alias = cache?.frontmatter?.alias ?? [];
const aliases = cache?.frontmatter?.aliases ?? [];

const allAliases: string[] = [
...[alias].flat(3),
...[aliases].flat(3),
];
if (allAliases.length) {
index += ` (${allAliases.join(", ")})`;
}
}

index += "\n";

if (!visited.hasOwnProperty(currNode)) {
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface BreadcrumbsSettings {
trailSeperator: string;
respectReadableLineLength: boolean;
wikilinkIndex: boolean;
aliasesInIndex: boolean;
debugMode: boolean;
superDebugMode: boolean;
}
Expand Down

0 comments on commit 670ae39

Please sign in to comment.