diff --git a/apps/desktop/src/lib/components/shared/command-menu/command.svelte b/apps/desktop/src/lib/components/shared/command-menu/command.svelte index 9f2a99d..4aea43e 100644 --- a/apps/desktop/src/lib/components/shared/command-menu/command.svelte +++ b/apps/desktop/src/lib/components/shared/command-menu/command.svelte @@ -4,7 +4,7 @@ import { getCollections, loadCollection } from '@/api/collection'; import { moveNote, openNote } from '@/api/notes'; import { activeFile, appTheme, collection } from '@/store'; - import { formatTimeAgo, shortcutToString } from '@/utils'; + import { formatTimeAgo, shortcutToString, formatFolderPath } from '@/utils'; import * as Command from '@haptic/ui/components/command'; import { open as browserOpen } from '@tauri-apps/api/shell'; import { Twitter } from 'lucide-svelte'; @@ -169,7 +169,7 @@ }} > - {folder.name.slice(1).replaceAll('/', ' > ')} + {formatFolderPath(folder.name)} {/if} {/each} @@ -194,7 +194,7 @@ }} > - {note.name.slice(1).replaceAll('/', ' > ')} + {formatFolderPath(note.name)} {/each} {:catch error} diff --git a/apps/desktop/src/lib/components/shared/editor/toolbar.svelte b/apps/desktop/src/lib/components/shared/editor/toolbar.svelte index 53d8840..b16d268 100644 --- a/apps/desktop/src/lib/components/shared/editor/toolbar.svelte +++ b/apps/desktop/src/lib/components/shared/editor/toolbar.svelte @@ -16,6 +16,7 @@ } from '@/store'; import Button from '@haptic/ui/components/button/button.svelte'; import { cn } from '@haptic/ui/lib/utils'; + import { formatDisplayName, formatActiveFileName } from '@/utils'; export let hideHistory: boolean = false; export let hideParentDirectories: boolean = false; @@ -148,7 +149,7 @@ 'text-foreground font-medium' )} > - {folder} + {formatDisplayName(folder)} {#if i !== ($activeFile?.replace($collection, '').split('/') ?? [])?.length - 1} @@ -162,7 +163,7 @@ scale="sm" class="h-6 text-[13px] w-fit px-1.5 text-foreground transition-all font-medium" > - {$activeFile?.replace($collection, '').split('/')?.slice(-1)[0] ?? ''} + {formatActiveFileName($activeFile, $collection)} {/if}

diff --git a/apps/desktop/src/lib/utils.ts b/apps/desktop/src/lib/utils.ts index 1c11527..62d4435 100644 --- a/apps/desktop/src/lib/utils.ts +++ b/apps/desktop/src/lib/utils.ts @@ -304,6 +304,31 @@ export const getNextUntitledName = (files: FileEntry[], prefix: string, extensio return `${prefix} ${maxNumber + 1}${extension}`; }; +export const formatDisplayName = (filename?: string): string => { + if (!filename) return ''; + return filename.endsWith('.md') ? filename.slice(0, -3) : filename; +}; + +export const formatFolderPath = (path?: string): string => { + if (!path) return ''; + return formatDisplayName(path.slice(1).replaceAll('/', ' > ')); +}; + +export const formatActiveFileName = (activeFile?: string, collection?: string): string => { + if (!activeFile) return ''; + const filename = + activeFile + .replace(collection || '', '') + .split('/') + .slice(-1)[0] || ''; + return formatDisplayName(filename); +}; + +export const formatFileNameFromPath = (path?: string): string => { + if (!path) return ''; + return formatDisplayName(path.split('/').pop() || ''); +}; + export const sortFileEntry = (a: FileEntry, b: FileEntry): number => { const isDirectory = (file: FileEntry) => file.children != null; if (isDirectory(a) && isDirectory(b)) { diff --git a/apps/desktop/src/routes/daily/entries.svelte b/apps/desktop/src/routes/daily/entries.svelte index 70791a2..69254b1 100644 --- a/apps/desktop/src/routes/daily/entries.svelte +++ b/apps/desktop/src/routes/daily/entries.svelte @@ -6,7 +6,7 @@ import { activeFile, platform } from '@/store'; import { cn } from '@haptic/ui/lib/utils'; import { deleteNote, openNote } from '@/api/notes'; - import { shortcutToString, showInFolder } from '@/utils'; + import { shortcutToString, showInFolder, formatDisplayName } from '@/utils'; import Shortcut from '@/components/shared/shortcut.svelte'; import { SHORTCUTS } from '@/constants'; import Label from '@haptic/ui/components/label/label.svelte'; @@ -121,7 +121,7 @@ options={SHORTCUTS['note:show-in-folder']} callback={() => showInFolder(entry.path)} /> - {entry.name} + {formatDisplayName(entry.name)} diff --git a/apps/desktop/src/routes/notes/entries.svelte b/apps/desktop/src/routes/notes/entries.svelte index 443882f..935646a 100644 --- a/apps/desktop/src/routes/notes/entries.svelte +++ b/apps/desktop/src/routes/notes/entries.svelte @@ -5,7 +5,7 @@ import Shortcut from '@/components/shared/shortcut.svelte'; import { SHORTCUTS } from '@/constants'; import { activeFile, collection, editor, platform } from '@/store'; - import { shortcutToString, showInFolder } from '@/utils'; + import { shortcutToString, showInFolder, formatDisplayName } from '@/utils'; import Button from '@haptic/ui/components/button/button.svelte'; import * as Collapsible from '@haptic/ui/components/collapsible'; import * as ContextMenu from '@haptic/ui/components/context-menu'; @@ -333,7 +333,7 @@ class={cn('w-[18px] h-[18px] shrink-0', !folderOpenStates[i] && 'hidden')} /> {entry.name}{formatDisplayName(entry.name)} @@ -506,7 +506,9 @@ options={SHORTCUTS['note:show-in-folder']} callback={() => !isRenaming && showInFolder(entry.path)} /> - {entry.name} + {formatDisplayName(entry.name)} diff --git a/apps/desktop/src/routes/notes/search-results.svelte b/apps/desktop/src/routes/notes/search-results.svelte index dd10943..9c659c5 100644 --- a/apps/desktop/src/routes/notes/search-results.svelte +++ b/apps/desktop/src/routes/notes/search-results.svelte @@ -1,6 +1,7 @@