diff --git a/src/App.tsx b/src/App.tsx index aa46594c..572d1815 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -71,6 +71,7 @@ import { invoke } from '@tauri-apps/api/core' import { isTauri, mockInvoke } from './mock-tauri' import type { SidebarSelection, InboxPeriod, VaultEntry, ViewDefinition } from './types' import type { NoteListItem } from './utils/ai-context' +import { initializeNoteProperties } from './utils/initializeNoteProperties' import { filterEntries, filterInboxEntries, type NoteListFilter } from './utils/noteListHelpers' import { openNoteInNewWindow } from './utils/openNoteWindow' import { isNoteWindow, getNoteWindowParams, getNoteWindowPathCandidates, findNoteWindowEntry, type NoteWindowParams } from './utils/windowMode' @@ -545,9 +546,7 @@ function App() { }) const handleInitializeProperties = useCallback(async (path: string) => { - const filename = path.split('/').pop()?.replace(/\.md$/, '') ?? 'Untitled' - await notes.handleUpdateFrontmatter(path, 'type', 'Note', { silent: true }) - await notes.handleUpdateFrontmatter(path, 'title', filename) + await initializeNoteProperties(notes.handleUpdateFrontmatter, path) }, [notes]) const handleRemoveNoteIcon = useCallback(async (path: string) => { diff --git a/src/utils/initializeNoteProperties.test.ts b/src/utils/initializeNoteProperties.test.ts new file mode 100644 index 00000000..a7903a6e --- /dev/null +++ b/src/utils/initializeNoteProperties.test.ts @@ -0,0 +1,19 @@ +import { describe, expect, it, vi } from 'vitest' + +import { initializeNoteProperties } from './initializeNoteProperties' + +describe('initializeNoteProperties', () => { + it('seeds only the Note type without creating a title field', async () => { + const updateFrontmatter = vi.fn().mockResolvedValue(undefined) + + await initializeNoteProperties(updateFrontmatter, '/vault/plain-note.md') + + expect(updateFrontmatter).toHaveBeenCalledTimes(1) + expect(updateFrontmatter).toHaveBeenCalledWith( + '/vault/plain-note.md', + 'type', + 'Note', + { silent: true }, + ) + }) +}) diff --git a/src/utils/initializeNoteProperties.ts b/src/utils/initializeNoteProperties.ts new file mode 100644 index 00000000..16fb4e01 --- /dev/null +++ b/src/utils/initializeNoteProperties.ts @@ -0,0 +1,13 @@ +export type UpdateFrontmatter = ( + path: string, + key: string, + value: string, + options?: { silent?: boolean }, +) => Promise + +export async function initializeNoteProperties( + updateFrontmatter: UpdateFrontmatter, + path: string, +): Promise { + await updateFrontmatter(path, 'type', 'Note', { silent: true }) +}