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:
@@ -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
|
||||
|
||||
@@ -172,9 +172,11 @@
|
||||
<span>
|
||||
{@html plugin.textProcessor.highlightText(title, matchesTitle)}
|
||||
</span>
|
||||
<span class="omnisearch-result__extension">
|
||||
.{getExtension(note.path)}
|
||||
</span>
|
||||
{#if !note.displayTitle}
|
||||
<span class="omnisearch-result__extension">
|
||||
.{getExtension(note.path)}
|
||||
</span>
|
||||
{/if}
|
||||
|
||||
<!-- Counter -->
|
||||
{#if note.matches.length > 0}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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.<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.`)
|
||||
)
|
||||
.addText(component => {
|
||||
|
||||
Reference in New Issue
Block a user