feat: Make any property of frontmatter a display name (#329)

This commit is contained in:
Simon Cambier
2024-06-29 17:02:11 +02:00
parent 94d687aeaa
commit 38c964bec2
6 changed files with 26 additions and 3 deletions

View File

@@ -221,10 +221,11 @@ export class CacheManager {
}
}
}
const displayTitle = metadata?.frontmatter?.[this.plugin.settings.displayTitle] ?? ''
const tags = getTagsFromMetadata(metadata)
return {
basename: file.basename,
displayTitle,
content,
/** Content without diacritics and markdown chars */
cleanedContent: stripMarkdownCharacters(removeDiacritics(content)),

View File

@@ -36,7 +36,7 @@
$: cleanedContent = plugin.textProcessor.makeExcerpt(note.content, note.matches[0]?.offset ?? -1)
$: glyph = false //cacheManager.getLiveDocument(note.path)?.doesNotExist
$: {
title = note.basename
title = note.displayTitle || note.basename
notePath = pathWithoutFilename(note.path)
// Icons

View File

@@ -46,6 +46,7 @@ export type DocumentRef = { path: string; mtime: number }
export type IndexedDocument = {
path: string
basename: string
displayTitle: string
mtime: number
content: string
@@ -76,6 +77,7 @@ export type ResultNote = {
score: number
path: string
basename: string
displayTitle: string
content: string
foundWords: string[]
matches: SearchMatch[]

View File

@@ -88,6 +88,7 @@ export class NotesIndexer {
return {
path: filename,
basename: name,
displayTitle: '',
mtime: 0,
content: '',

View File

@@ -154,8 +154,9 @@ export class SearchEngine {
term.length <= 3 ? 0 : term.length <= 5 ? fuzziness / 2 : fuzziness,
boost: {
basename: settings.weightBasename,
directory: settings.weightDirectory,
aliases: settings.weightBasename,
displayTitle: settings.weightBasename,
directory: settings.weightDirectory,
headings1: settings.weightH1,
headings2: settings.weightH2,
headings3: settings.weightH3,

View File

@@ -37,6 +37,8 @@ export interface OmnisearchSettings extends WeightingSettings {
/** Extensions of plain text files to index, in addition to .md */
indexedFileTypes: string[]
/** Custom title field */
displayTitle: string
/** Enable PDF indexing */
PDFIndexing: boolean
/** Enable Images indexing */
@@ -209,6 +211,21 @@ export class SettingsTab extends PluginSettingTab {
})
})
// Custom display title
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>
Leave empty to disable.`)
)
.addText(component => {
component.setValue(settings.displayTitle).onChange(async v => {
await clearCacheDebounced()
settings.displayTitle = v
await saveSettings(this.plugin)
})
})
// Additional text files to index
new Setting(containerEl)
.setName('Additional TEXT files to index')
@@ -737,6 +754,7 @@ export function getDefaultSettings(app: App): OmnisearchSettings {
ignoreDiacritics: true,
ignoreArabicDiacritics: false,
indexedFileTypes: [] as string[],
displayTitle: '',
PDFIndexing: false,
officeIndexing: false,
imagesIndexing: false,