generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.ts
42 lines (36 loc) · 1.23 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Plugin } from 'obsidian';
export default class FrontmatterAliasDisplay extends Plugin {
displayAliases() {
const fileExplorer = app.workspace.getLeavesOfType('file-explorer')[0];
let files = fileExplorer.view.fileItems;
for (const file of Object.values(files)) {
if (file.file) {
const aliasDiv = file.selfEl.querySelector('.file-alias')
if ( aliasDiv ) {
aliasDiv.remove();
}
let aliases = app.metadataCache.getFileCache(file.file)?.frontmatter?.aliases;
let alias = app.metadataCache.getFileCache(file.file)?.frontmatter?.alias;
let aliasContent = alias ? alias : aliases;
file.selfEl.createEl('div', {text: aliasContent, cls: 'file-alias nav-file-title-content'});
}
}
}
async onload() {
app.workspace.onLayoutReady(this.displayAliases);
app.workspace.on("layout-change", this.displayAliases);
app.workspace.on("editor-change", this.displayAliases);
}
onunload() {
const fileExplorer = app.workspace.getLeavesOfType('file-explorer')[0];
let files = fileExplorer.view.fileItems;
for (const file of Object.values(files)) {
if (file.file) {
const aliasDiv = file.selfEl.querySelector('.file-alias')
if ( aliasDiv ) {
aliasDiv.remove();
}
}
}
}
}