diff --git a/main.ts b/main.ts index 26b0db1..47da264 100644 --- a/main.ts +++ b/main.ts @@ -83,6 +83,10 @@ export default class Blockreffer extends Plugin { if (cache && cache.blocks) { const fileContent = await app.vault.cachedRead(file); + const aliases = cache.frontmatter && cache.frontmatter.aliases ? + cache.frontmatter.aliases : + []; + for (const [id] of Object.entries(cache.blocks)) { const blockContent = fileContent.slice( cache.blocks[id].position.start.offset, @@ -92,6 +96,7 @@ export default class Blockreffer extends Plugin { file: file, id: id, content: blockContent.trim(), + aliases: aliases }); } } @@ -113,6 +118,7 @@ interface BlockSuggestion { file: TFile; id: string; content: string; + aliases: string[]; } type BlockRefAction = "embed" | "open"; @@ -175,13 +181,14 @@ class BlockSearchModal extends FuzzySuggestModal { // fuzzy-searchable content getItemText(item: BlockSuggestion): string { - let toSearch = "" + const toSearch = [] - if (this.plugin.settings.toSearch.content) toSearch += item.content.replace(`^${item.id}`, "").trim(); - if (this.plugin.settings.toSearch.path ) toSearch += item.file.path; - if (this.plugin.settings.toSearch.id ) toSearch += item.id; + if (this.plugin.settings.toSearch.content) toSearch.push(item.content.replace(`^${item.id}`, "").trim()); + if (this.plugin.settings.toSearch.path ) toSearch.push(item.file.path); + if (this.plugin.settings.toSearch.id ) toSearch.push(item.id); + if (this.plugin.settings.toSearch.aliases) toSearch.push(item.aliases.join(" ")) - return toSearch; + return toSearch.join(" "); } renderSuggestion({ item }: FuzzyMatch, el: HTMLElement) { diff --git a/settings/settings.ts b/settings/settings.ts index 6088560..ea03334 100644 --- a/settings/settings.ts +++ b/settings/settings.ts @@ -23,6 +23,9 @@ export interface BlockrefferSettings { /** Whether to search for matches by file ID. */ id: boolean; + + /** Whether to search for matches by file aliases. */ + aliases: boolean; }; /** Maximum number of search results to display. */ @@ -43,9 +46,10 @@ export const DEFAULT_SETTINGS: BlockrefferSettings = { toSearch: { content: true, path: true, - id: true + id: true, + aliases: true }, searchLimit: 10, removeIdFromContent: true, fileName: "base" as const, -} \ No newline at end of file +} diff --git a/settings/settingsTab.ts b/settings/settingsTab.ts index 7e1d4af..7dd8efc 100644 --- a/settings/settingsTab.ts +++ b/settings/settingsTab.ts @@ -168,5 +168,16 @@ export class BlockrefferSettingTab extends PluginSettingTab { await this.plugin.saveSettings(); }) ); + + new Setting(containerEl) + .setName("File aliases") + .setDesc("Search for file aliases.") + .addToggle(toggle => toggle + .setValue(this.plugin.settings.toSearch.aliases) + .onChange(async (value) => { + this.plugin.settings.toSearch.aliases = value + await this.plugin.saveSettings(); + }) + ); } -} \ No newline at end of file +}