-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
85 lines (71 loc) · 2.32 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import {App, LinkCache, MarkdownView, Modal, Plugin, PluginSettingTab, Setting, TFile} from 'obsidian';
import {BuilderExt} from "./plugin";
import {addIconsToDOM, insertIconToNode} from "./utils";
import {ExplorerView, FileItem} from "./@types/obsidian";
import {Prec} from "@codemirror/state";
// Remember to rename these classes and interfaces!
export interface ExtraMarginSettings {
top?: number;
right?: number;
bottom?: number;
left?: number;
}
interface MyPluginSettings {
size: number;
borderRadius: number;
extraMargin: ExtraMarginSettings;
}
const DEFAULT_SETTINGS: MyPluginSettings = {
size: 32,
borderRadius: 10,
extraMargin: {
top: 0,
right: 4,
bottom: 0,
left: 0,
},
};
export default class MyPlugin extends Plugin {
settings: MyPluginSettings;
notesWithEmbed = new Map<string, string>;
private registeredFileExplorers = new Set<ExplorerView>();
async onload() {
await this.loadSettings();
this.app.workspace.onLayoutReady(() => this.checkNotesAndMount());
this.registerEvent(this.app.workspace.on('layout-change', () => this.onMount()));
//this.registerExtensions([emojiListField], 'markdown');
this.registerEditorExtension([Prec.lowest(BuilderExt(this))])//emojiListPlugin
//this.registerEditorExtension(Prec.lowest(asyncDecoBuilderExt(this)));
}
async checkNotesAndMount() {
const pictureExtensions = ["jpg", "jpeg", "png", "webp", "bmp", "svg", "gif", "ico"];
const allNotes = this.app.vault.getMarkdownFiles();
for (const note of allNotes) {
const metadata = this.app.metadataCache.getFileCache(note)
//console.log('metadata', metadata);
if (metadata && metadata.embeds && metadata.embeds.length > 0) {
for (const embed of metadata.embeds) {
const embedFile = this.app.metadataCache.getFirstLinkpathDest(embed.link, note.parent.path);
if (!embedFile) {
continue;
}
//console.log('embedFile', embedFile);
if (pictureExtensions.includes(embedFile.extension)) {
this.notesWithEmbed.set(note.path, embedFile.path);
break;
}
}
}
}
//console.log('this.notesWithEmbed', this.notesWithEmbed);
await this.onMount();
}
async onMount() {
addIconsToDOM(this, this.notesWithEmbed, this.registeredFileExplorers);
}
onunload() {
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
}