Skip to content

Commit

Permalink
feat(Path View): ✨ Option to hide trail in specific notes using custo…
Browse files Browse the repository at this point in the history
…m metadata field
  • Loading branch information
SkepticMystic committed Aug 29, 2021
1 parent 24d6aac commit f5d96bf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
15 changes: 15 additions & 0 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,21 @@ export class BreadcrumbsSettingTab extends PluginSettingTab {
})
);


new Setting(trailDetails)
.setName("Field name to hide trail")
.setDesc(
"A note-specific toggle to hide the Trail View. By default, it is `hide-trail`. So, to hide the trail on a specific note, add the field to that note's yaml, like so: `hide-trail: {{anything}}`."
)
.addText((text) => {
text
.setValue(settings.hideTrailFieldName);
text.inputEl.onblur = async () => {
settings.hideTrailFieldName = text.getValue();
await plugin.saveSettings();
}
});

new Setting(trailDetails)
.setName("Trail or Table or Both")
.setDesc(
Expand Down
15 changes: 8 additions & 7 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface BreadcrumbsSettings {
filterImpliedSiblingsOfDifferentTypes: boolean;
rlLeaf: boolean;
showTrail: boolean;
hideTrailFieldName: string;
trailOrTable: 1 | 2 | 3;
gridDots: boolean;
dotsColour: string;
Expand All @@ -40,13 +41,13 @@ export interface BreadcrumbsSettings {
export interface dvFrontmatterCache {
file: TFile;
[field: string]:
| string
| string[]
| string[][]
| dvLink
| dvLink[]
| Pos
| TFile;
| string
| string[]
| string[][]
| dvLink
| dvLink[]
| Pos
| TFile;
}

export type Directions = "up" | "same" | "down";
Expand Down
23 changes: 18 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const DEFAULT_SETTINGS: BreadcrumbsSettings = {
filterImpliedSiblingsOfDifferentTypes: false,
rlLeaf: true,
showTrail: true,
hideTrailFieldName: 'hide-trail',
trailOrTable: 3,
gridDots: false,
dotsColour: "#000000",
Expand Down Expand Up @@ -90,6 +91,7 @@ declare module "obsidian" {
}
}


export default class BreadcrumbsPlugin extends Plugin {
settings: BreadcrumbsSettings;
visited: [string, HTMLDivElement][];
Expand Down Expand Up @@ -185,6 +187,10 @@ export default class BreadcrumbsPlugin extends Plugin {

this.registerEvent(this.activeLeafChangeEventRef);

// const editorToggleEventRef = this.app.workspace.on('markdown:toggle-preview', () => { console.log('working') })

// this.registerEvent(editorToggleEventRef)

// ANCHOR autorefresh interval
if (this.settings.refreshIntervalTime > 0) {
this.refreshIntervalID = window.setInterval(async () => {
Expand Down Expand Up @@ -669,14 +675,24 @@ export default class BreadcrumbsPlugin extends Plugin {
debugGroupEnd(settings, "debugMode");
return;
}

const activeMDView = this.app.workspace.getActiveViewOfType(MarkdownView);
const currFile = activeMDView.file;
const currMetadata = this.app.metadataCache.getFileCache(currFile);

const previewView = activeMDView.contentEl.querySelector(
".markdown-preview-view"
);
if (currMetadata.frontmatter?.hasOwnProperty(settings.hideTrailFieldName)) {
debugGroupEnd(settings, "debugMode");
previewView.querySelector("div.breadcrumbs-trail")?.remove();
return;
}

if (!activeMDView) {
debugGroupEnd(settings, "debugMode");
return;
}

const currFile = activeMDView.file;
const frontm =
this.app.metadataCache.getFileCache(currFile)?.frontmatter ?? {};
if (frontm["kanban-plugin"]) {
Expand All @@ -689,9 +705,6 @@ export default class BreadcrumbsPlugin extends Plugin {
debug(settings, { sortedTrails });

// Get the container div of the active note
const previewView = activeMDView.contentEl.querySelector(
".markdown-preview-view"
);
// Make sure it's empty
previewView.querySelector("div.breadcrumbs-trail")?.remove();

Expand Down

0 comments on commit f5d96bf

Please sign in to comment.