Skip to content

Commit

Permalink
fix: Normalize aliases on startup too
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Sep 30, 2023
1 parent 127bcdb commit d850b8f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/util/linkify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ declare module "obsidian" {

class LinkifierClass extends Component {
#cache: Map<string, string> = new Map();
#addAliasesToCache(aliases: string[], file: TFile) {
for (const alias of aliases) {
this.#cache.set(alias, file.name);
this.#cache.set(alias.toLowerCase(), file.name);
}
}
buildCache() {
//defer this
setTimeout(() => {
const links = app.metadataCache.getLinkSuggestions();
for (const { alias, file } of links) {
if (!alias) continue;
this.#cache.set(alias, file.name);
this.#addAliasesToCache([alias], file);
}
}, 0);
}
Expand Down Expand Up @@ -53,10 +59,7 @@ class LinkifierClass extends Component {
app.metadataCache.getFileCache(file) ?? {};
if (!frontmatter) return;
const aliases = parseFrontMatterAliases(frontmatter) ?? [];
for (const alias of aliases) {
this.#cache.set(alias, file.name);
this.#cache.set(alias.toLowerCase(), file.name);
}
this.#addAliasesToCache(aliases, file);
})
);
}
Expand Down

0 comments on commit d850b8f

Please sign in to comment.