Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -92,6 +96,7 @@ export default class Blockreffer extends Plugin {
file: file,
id: id,
content: blockContent.trim(),
aliases: aliases
});
}
}
Expand All @@ -113,6 +118,7 @@ interface BlockSuggestion {
file: TFile;
id: string;
content: string;
aliases: string[];
}

type BlockRefAction = "embed" | "open";
Expand Down Expand Up @@ -175,13 +181,14 @@ class BlockSearchModal extends FuzzySuggestModal<BlockSuggestion> {

// 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<BlockSuggestion>, el: HTMLElement) {
Expand Down
8 changes: 6 additions & 2 deletions settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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,
}
}
13 changes: 12 additions & 1 deletion settings/settingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
})
);
}
}
}