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