feat: Allow #heading as display title setting (#434)

* feat: Allow #heading as display name setting

* Add displayTitle usage to create markdown link

* Tweak description text

* Address comments
This commit is contained in:
Eli W. Hunter
2025-01-29 03:45:14 -05:00
committed by GitHub
parent 8d52c2023b
commit 9d7f4183cf
4 changed files with 15 additions and 8 deletions

View File

@@ -240,9 +240,10 @@
// Generate link // Generate link
let link: string let link: string
if (file && active) { if (file && active) {
link = plugin.app.fileManager.generateMarkdownLink(file, active.path) link = plugin.app.fileManager.generateMarkdownLink(file, active.path, "", selectedNote.displayTitle)
} else { } else {
link = `[[${selectedNote.basename}.${getExtension(selectedNote.path)}]]` const maybeDisplayTitle = selectedNote.displayTitle === "" ? "" : `|${selectedNote.displayTitle}`
link = `[[${selectedNote.basename}.${getExtension(selectedNote.path)}${maybeDisplayTitle}]]`
} }
// Inject link // Inject link

View File

@@ -172,9 +172,11 @@
<span> <span>
{@html plugin.textProcessor.highlightText(title, matchesTitle)} {@html plugin.textProcessor.highlightText(title, matchesTitle)}
</span> </span>
{#if !note.displayTitle}
<span class="omnisearch-result__extension"> <span class="omnisearch-result__extension">
.{getExtension(note.path)} .{getExtension(note.path)}
</span> </span>
{/if}
<!-- Counter --> <!-- Counter -->
{#if note.matches.length > 0} {#if note.matches.length > 0}

View File

@@ -215,8 +215,12 @@ export class DocumentsRepository {
} }
} }
} }
const displayTitle = let displayTitle: string
metadata?.frontmatter?.[this.plugin.settings.displayTitle] ?? '' 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) const tags = getTagsFromMetadata(metadata)
return { return {
basename: file.basename, basename: file.basename,

View File

@@ -242,7 +242,7 @@ export class SettingsTab extends PluginSettingTab {
new Setting(containerEl) new Setting(containerEl)
.setName('Set frontmatter property key as title') .setName('Set frontmatter property key as title')
.setDesc( .setDesc(
htmlDescription(`If you have a custom property in your notes that you want to use as the title in search results.<br> 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.<br>
Leave empty to disable.`) Leave empty to disable.`)
) )
.addText(component => { .addText(component => {