-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathPublishFileAPI.ts
More file actions
51 lines (39 loc) · 1.6 KB
/
PublishFileAPI.ts
File metadata and controls
51 lines (39 loc) · 1.6 KB
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
import { FileAPI } from 'packages/core/src/api/FileAPI';
import type { ButtonPaneType } from 'packages/core/src/config/ButtonConfig';
import type { PublishComponents } from 'packages/publish/src/main';
export class PublishFileAPI extends FileAPI<PublishComponents> {
public read(_filePath: string): Promise<string> {
throw new Error('Reading files is not supported in Obsidian Publish.');
}
public write(_filePath: string, _content: string): Promise<void> {
throw new Error('Writing files is not supported in Obsidian Publish.');
}
public exists(filePath: string): Promise<boolean> {
return Promise.resolve(this.getAllFiles().contains(filePath));
}
public atomicModify(_filePath: string, _modify: (content: string) => string): Promise<void> {
throw new Error('Modifying files is not supported in Obsidian Publish.');
}
public create(_folderPath: string, _fileName: string, _extension: string, _open?: boolean): Promise<string> {
throw new Error('Creating files is not supported in Obsidian Publish.');
}
public getAllFiles(): string[] {
return Object.keys(publish.site.cache);
}
public getAllFolders(): string[] {
const filePaths = this.getAllFiles();
const folders = new Set<string>();
for (const filePath of filePaths) {
const parts = filePath.split('/');
parts.pop();
folders.add(parts.join('/'));
}
return Array.from(folders);
}
public open(_filePath: string, _callingFilePath: string, _paneType: ButtonPaneType | boolean): Promise<void> {
throw new Error('not implemented');
}
public getPathByName(name: string, _relativeTo?: string): string | undefined {
return name;
}
}