Skip to content

Commit

Permalink
feat: Make any property of frontmatter a display name (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
scambier committed Jun 29, 2024
1 parent 94d687a commit 38c964b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/cache-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
2 changes: 1 addition & 1 deletion src/components/ResultItemVault.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type DocumentRef = { path: string; mtime: number }
export type IndexedDocument = {
path: string
basename: string
displayTitle: string
mtime: number

content: string
Expand Down Expand Up @@ -76,6 +77,7 @@ export type ResultNote = {
score: number
path: string
basename: string
displayTitle: string
content: string
foundWords: string[]
matches: SearchMatch[]
Expand Down
1 change: 1 addition & 0 deletions src/notes-indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class NotesIndexer {
return {
path: filename,
basename: name,
displayTitle: '',
mtime: 0,

content: '',
Expand Down
3 changes: 2 additions & 1 deletion src/search/search-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -737,6 +754,7 @@ export function getDefaultSettings(app: App): OmnisearchSettings {
ignoreDiacritics: true,
ignoreArabicDiacritics: false,
indexedFileTypes: [] as string[],
displayTitle: '',
PDFIndexing: false,
officeIndexing: false,
imagesIndexing: false,
Expand Down

0 comments on commit 38c964b

Please sign in to comment.