Hide duplicated folder note name in path

This commit is contained in:
Paul 2026-03-10 15:49:50 +01:00
parent 7c41751c34
commit 8344490906
6 changed files with 90 additions and 36 deletions

View file

@ -1,6 +1,6 @@
import { Keymap, Platform } from 'obsidian';
import type FolderNotesPlugin from 'src/main';
import { getFolderNote } from 'src/functions/folderNoteFunctions';
import { getFolderNote, getFolderNoteFolder } from 'src/functions/folderNoteFunctions';
import { handleViewHeaderClick } from './handleClick';
import { getExcludedFolder } from 'src/ExcludeFolders/functions/folderFunctions';
import { updateCSSClassesForFolder } from 'src/functions/styleFunctions';
@ -162,10 +162,23 @@ async function updateFolderNamesInPath(
plugin: FolderNotesPlugin,
titleContainer: HTMLElement,
): Promise<void> {
const headers = titleContainer.querySelectorAll('span.view-header-breadcrumb');
const titleParent = titleContainer.querySelector('.view-header-title-parent');
let path = '';
const TRAILING_SLASH_LENGTH = 1;
headers.forEach(async (breadcrumb: HTMLElement) => {
if (titleParent?.childNodes.length === 0) {
titleContainer.classList.remove('hide-folder-note-title-in-path');
}
// eslint-disable-next-line complexity
titleParent?.childNodes.forEach(async (breadcrumb: HTMLElement) => {
if (!(breadcrumb instanceof HTMLElement)) return;
if (breadcrumb.classList.contains('view-header-breadcrumb-separator')) {
if (breadcrumb.nextSibling === null) {
breadcrumb.classList.add('is-last-separator');
}
return;
}
path += breadcrumb.getAttribute('old-name') ?? (breadcrumb as HTMLElement).innerText.trim();
path += '/';
const folderPath = path.slice(0, -TRAILING_SLASH_LENGTH);
@ -173,6 +186,21 @@ async function updateFolderNamesInPath(
const excludedFolder = getExcludedFolder(plugin, folderPath, true);
if (excludedFolder?.disableFolderNote) return;
const folderNote = getFolderNote(plugin, folderPath);
const viewHeaderTitle = titleContainer.querySelector('.view-header-title');
if (viewHeaderTitle) {
const filePath = path + (viewHeaderTitle as HTMLElement).innerText.trim() + '.md';
const file = plugin.app.vault.getAbstractFileByPath(
filePath);
const folder = getFolderNoteFolder(plugin, file?.path ?? '', file?.name ?? '');
if (folder && file && file.path === folderNote?.path && file.parent?.path !== '/') {
viewHeaderTitle.parentElement?.classList.add('hide-folder-note-title-in-path');
viewHeaderTitle.classList.add('path-is-folder-note');
} else {
viewHeaderTitle.parentElement?.classList.remove('hide-folder-note-title-in-path');
viewHeaderTitle.classList.remove('path-is-folder-note');
}
}
if (!folderNote) return;
if (folderNote) breadcrumb.classList.add('has-folder-note');
breadcrumb?.setAttribute('data-path', path.slice(0, -TRAILING_SLASH_LENGTH));

View file

@ -49,9 +49,9 @@ export function getFileExplorer(
if (!leaf) { return undefined; }
/* make.md plugin integration */
if ((leaf.containerEl?.lastChild as HTMLElement)?.dataset?.type == 'mk-path-view') {
if ((leaf.containerEl?.lastChild as HTMLElement)?.dataset?.type === 'mk-path-view') {
plugin.app.workspace.iterateAllLeaves((x) => {
if ((x as FileExplorerWorkspaceLeaf).tabHeaderEl?.dataset?.type == 'file-explorer') {
if ((x as FileExplorerWorkspaceLeaf).tabHeaderEl?.dataset?.type === 'file-explorer') {
leaf = x as FileExplorerWorkspaceLeaf;
}
});

View file

@ -59,37 +59,7 @@ export default class FolderNotesPlugin extends Plugin {
this.fvIndexDB = new FvIndexDB(this);
// Add CSS Classes
document.body.classList.add('folder-notes-plugin');
if (this.settings.hideFolderNote) { document.body.classList.add('hide-folder-note'); }
if (this.settings.hideCollapsingIconForEmptyFolders) {
document.body.classList.add('fn-hide-empty-collapse-icon');
}
if (this.settings.underlineFolder) { document.body.classList.add('folder-note-underline'); }
if (this.settings.boldName) { document.body.classList.add('folder-note-bold'); }
if (this.settings.cursiveName) { document.body.classList.add('folder-note-cursive'); }
if (this.settings.boldNameInPath) { document.body.classList.add('folder-note-bold-path'); }
if (this.settings.cursiveNameInPath) {
document.body.classList.add('folder-note-cursive-path');
}
if (this.settings.underlineFolderInPath) {
document.body.classList.add('folder-note-underline-path');
}
if (this.settings.stopWhitespaceCollapsing) {
document.body.classList.add('fn-whitespace-stop-collapsing');
}
if (this.settings.hideCollapsingIcon) {
document.body.classList.add('fn-hide-collapse-icon');
}
if (this.settings.ignoreAttachmentFolder) {
document.body.classList.add('fn-ignore-attachment-folder');
}
if (!this.settings.highlightFolder) {
document.body.classList.add('disable-folder-highlight');
}
if (requireApiVersion('1.7.2')) {
document.body.classList.add('version-1-7-2');
}
this.addSettingCssClasses();
new Commands(this.app, this).registerCommands();
registerOverviewCommands(this);
@ -161,6 +131,43 @@ export default class FolderNotesPlugin extends Plugin {
);
}
addSettingCssClasses(): void {
document.body.classList.add('folder-notes-plugin');
if (this.settings.hideFolderNote) { document.body.classList.add('hide-folder-note'); }
if (this.settings.hideCollapsingIconForEmptyFolders) {
document.body.classList.add('fn-hide-empty-collapse-icon');
}
if (this.settings.hideFolderNoteNameInPath) {
document.body.classList.add('folder-note-hide-name-path');
}
if (this.settings.underlineFolder) { document.body.classList.add('folder-note-underline'); }
if (this.settings.boldName) { document.body.classList.add('folder-note-bold'); }
if (this.settings.cursiveName) { document.body.classList.add('folder-note-cursive'); }
if (this.settings.boldNameInPath) { document.body.classList.add('folder-note-bold-path'); }
if (this.settings.cursiveNameInPath) {
document.body.classList.add('folder-note-cursive-path');
}
if (this.settings.underlineFolderInPath) {
document.body.classList.add('folder-note-underline-path');
}
if (this.settings.stopWhitespaceCollapsing) {
document.body.classList.add('fn-whitespace-stop-collapsing');
}
if (this.settings.hideCollapsingIcon) {
document.body.classList.add('fn-hide-collapse-icon');
}
if (this.settings.ignoreAttachmentFolder) {
document.body.classList.add('fn-ignore-attachment-folder');
}
if (!this.settings.highlightFolder) {
document.body.classList.add('disable-folder-highlight');
}
if (requireApiVersion('1.7.2')) {
document.body.classList.add('version-1-7-2');
}
}
onLayoutReady(): void {
if (!this._loaded) {
return;

View file

@ -113,4 +113,17 @@ export async function renderPath(settingsTab: SettingsTab): Promise<void> {
await settingsTab.plugin.saveSettings();
}),
);
new Setting(containerEl)
.setName('Hide folder note name in the path')
.setDesc('Only show the folder name in the path and hide the folder note name.')
.addToggle((toggle) =>
toggle
.setValue(settingsTab.plugin.settings.hideFolderNoteNameInPath)
.onChange(async (value) => {
document.body.classList.toggle('folder-note-hide-name-path', value);
settingsTab.plugin.settings.hideFolderNoteNameInPath = value;
await settingsTab.plugin.saveSettings();
}),
);
}

View file

@ -82,6 +82,7 @@ export interface FolderNotesSettings {
fvGlobalSettings: {
autoUpdateLinks: boolean;
}
hideFolderNoteNameInPath: boolean;
}
export const DEFAULT_SETTINGS: FolderNotesSettings = {
@ -206,6 +207,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
fvGlobalSettings: {
autoUpdateLinks: false,
},
hideFolderNoteNameInPath: false,
};
export class SettingsTab extends PluginSettingTab {

View file

@ -222,6 +222,10 @@ li:has(.fv-link-list-item),
.folder-note-cursive-path .has-folder-note.view-header-breadcrumb {
font-style: italic;
}
.folder-note-hide-name-path .hide-folder-note-title-in-path .is-last-separator,
.folder-note-hide-name-path .hide-folder-note-title-in-path .path-is-folder-note {
display: none;
}
/* Collapse Icon Handling */