Skip to content

Commit

Permalink
feat(CreateIndex): Add setting to toggle wikilinks in index
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jul 21, 2021
1 parent 45e2650 commit b76f919
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
18 changes: 18 additions & 0 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,24 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
})
);

const createIndexDetails: HTMLDetailsElement =
containerEl.createEl("details");
createIndexDetails.createEl("summary", { text: "Create Index" });

new Setting(createIndexDetails)
.setName("Add wiklink brackets")
.setDesc(
"When creating an index, should it wrap the note name in wikilinks `[[]]` or not. On = yes, off = no."
)
.addToggle((toggle) =>
toggle
.setValue(plugin.settings.wikilinkIndex)
.onChange(async (value) => {
plugin.settings.wikilinkIndex = value;
await plugin.saveSettings();
})
);

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

Expand Down
22 changes: 17 additions & 5 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import type { Graph } from "graphlib";
import { ItemView, TFile, WorkspaceLeaf } from "obsidian";
import { closeImpliedLinks, debug } from "src/sharedFunctions";
import {
DATAVIEW_INDEX_DELAY,
TRAIL_ICON,
VIEW_TYPE_BREADCRUMBS_MATRIX,
} from "src/constants";
import type { internalLinkObj, SquareProps } from "src/interfaces";
import type {
BreadcrumbsSettings,
internalLinkObj,
SquareProps,
} from "src/interfaces";
import type BreadcrumbsPlugin from "src/main";
import { closeImpliedLinks, debug, dropMD } from "src/sharedFunctions";
import Lists from "./Lists.svelte";
import Matrix from "./Matrix.svelte";

Expand Down Expand Up @@ -125,7 +129,11 @@ export default class MatrixView extends ItemView {
return pathsArr;
}

createIndex(allPaths: string[][], currFile: string): string {
createIndex(
allPaths: string[][],
currFile: string,
settings: BreadcrumbsSettings
): string {
const reversed = allPaths.map((path) => path.reverse());
reversed.forEach((path) => path.shift());

Expand All @@ -143,7 +151,11 @@ export default class MatrixView extends ItemView {
) {
continue;
} else {
txt += `${indent.repeat(depth)} - [[${currNode}]]\n`;
txt += `${indent.repeat(depth)}- `;
txt += settings.wikilinkIndex ? "[[" : "";
txt += currNode;
txt += settings.wikilinkIndex ? "]]" : "";
txt += "\n";

if (!visited.hasOwnProperty(currNode)) {
visited[currNode] = [];
Expand Down Expand Up @@ -184,7 +196,7 @@ export default class MatrixView extends ItemView {
text: "Create Index",
});
createIndexButton.addEventListener("click", () => {
console.log(this.createIndex(allPaths, currFile.basename));
console.log(this.createIndex(allPaths, currFile.basename, settings));
});

const [parentFieldName, siblingFieldName, childFieldName] = [
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface BreadcrumbsSettings {
noPathMessage: string;
trailSeperator: string;
respectReadableLineLength: boolean;
wikilinkIndex: boolean;
debugMode: boolean;
superDebugMode: boolean;
}
Expand All @@ -27,7 +28,7 @@ export interface JugglLink {
links: {
type: string;
linksInLine: string[];
}[]
}[];
}

export interface neighbourObj {
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const DEFAULT_SETTINGS: BreadcrumbsSettings = {
noPathMessage: `This note has no real or implied parents`,
trailSeperator: "→",
respectReadableLineLength: true,
wikilinkIndex: true,
debugMode: false,
superDebugMode: false,
};
Expand Down

0 comments on commit b76f919

Please sign in to comment.