From 670ae39b430eb5c8eb93f2d5b5951090add7f30f Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Sat, 31 Jul 2021 20:55:53 +0200 Subject: [PATCH] feat(CreateIndex): :sparkles: Setting to show aliases in index --- src/BreadcrumbsSettingTab.ts | 13 ++++++++++++ src/MatrixView.ts | 39 ++++++++++++++++++++---------------- src/interfaces.ts | 1 + 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/BreadcrumbsSettingTab.ts b/src/BreadcrumbsSettingTab.ts index d6d5344a..2e3e96fc 100644 --- a/src/BreadcrumbsSettingTab.ts +++ b/src/BreadcrumbsSettingTab.ts @@ -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" }); diff --git a/src/MatrixView.ts b/src/MatrixView.ts index 0ba5ce8d..a071e819 100644 --- a/src/MatrixView.ts +++ b/src/MatrixView.ts @@ -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"), @@ -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) => { @@ -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 }); @@ -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); @@ -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)) { diff --git a/src/interfaces.ts b/src/interfaces.ts index 634f4b79..0ea5142b 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -21,6 +21,7 @@ export interface BreadcrumbsSettings { trailSeperator: string; respectReadableLineLength: boolean; wikilinkIndex: boolean; + aliasesInIndex: boolean; debugMode: boolean; superDebugMode: boolean; }