diff --git a/src/components/ModalVault.svelte b/src/components/ModalVault.svelte index c7b7473..ad55ae0 100644 --- a/src/components/ModalVault.svelte +++ b/src/components/ModalVault.svelte @@ -240,9 +240,10 @@ // Generate link let link: string if (file && active) { - link = plugin.app.fileManager.generateMarkdownLink(file, active.path) + link = plugin.app.fileManager.generateMarkdownLink(file, active.path, "", selectedNote.displayTitle) } else { - link = `[[${selectedNote.basename}.${getExtension(selectedNote.path)}]]` + const maybeDisplayTitle = selectedNote.displayTitle === "" ? "" : `|${selectedNote.displayTitle}` + link = `[[${selectedNote.basename}.${getExtension(selectedNote.path)}${maybeDisplayTitle}]]` } // Inject link diff --git a/src/components/ResultItemVault.svelte b/src/components/ResultItemVault.svelte index a411825..cc3dd55 100644 --- a/src/components/ResultItemVault.svelte +++ b/src/components/ResultItemVault.svelte @@ -172,9 +172,11 @@ {@html plugin.textProcessor.highlightText(title, matchesTitle)} - - .{getExtension(note.path)} - + {#if !note.displayTitle} + + .{getExtension(note.path)} + + {/if} {#if note.matches.length > 0} diff --git a/src/repositories/documents-repository.ts b/src/repositories/documents-repository.ts index 7aac7a1..9d0dbf4 100644 --- a/src/repositories/documents-repository.ts +++ b/src/repositories/documents-repository.ts @@ -215,8 +215,12 @@ export class DocumentsRepository { } } } - const displayTitle = - metadata?.frontmatter?.[this.plugin.settings.displayTitle] ?? '' + let displayTitle: string + if (this.plugin.settings.displayTitle === '#heading') { + displayTitle = metadata?.headings?.find(h => h.level === 1)?.heading ?? '' + } else { + displayTitle = metadata?.frontmatter?.[this.plugin.settings.displayTitle] ?? '' + } const tags = getTagsFromMetadata(metadata) return { basename: file.basename, diff --git a/src/settings.ts b/src/settings.ts index 425adbb..d00b5b0 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -242,7 +242,7 @@ export class SettingsTab extends PluginSettingTab { new Setting(containerEl) .setName('Set frontmatter property key as title') .setDesc( - htmlDescription(`If you have a custom property in your notes that you want to use as the title in search results.
+ htmlDescription(`If you have a custom property in your notes that you want to use as the title in search results. If you set this to '#heading', then use the first heading from a file as the title.
Leave empty to disable.`) ) .addText(component => {