generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
30 lines (28 loc) · 732 Bytes
/
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
import {Plugin} from 'obsidian';
export default class ZettelCraft extends Plugin {
async onload() {
this.addCommand({
id: 'create-new-note',
name: 'Create new note',
callback: async () => {
await this.createNewNote();
}
});
}
async createNewNote() {
const now = window.moment();
const id = now.format('YYYYMMDDHHmm');
let data = '---\n';
data += `id: ${id}\n`;
data += 'title: \n';
data += '---\n'
data += '\n';
data += `# ${id} \n`;
const file = await this.app.vault.create(`${id}.md`, data);
await this.app.workspace.getLeaf('tab').openFile(file);
this.app.workspace.activeEditor?.editor?.setSelections([
{ anchor: { ch: 7, line: 2}},
{ anchor: { ch: 15, line: 5}},
]);
}
}