Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Dec 5, 2023
2 parents 89fb005 + 2f10f57 commit a9e7a09
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
19 changes: 9 additions & 10 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"id": "relay-md",
"name": "Relay.md",
"version": "1.4.0",
"minAppVersion": "0.15.0",
"description": "Markdown workflows for teams.",
"author": "xeroc",
"authorUrl": "https://chainsquad.com",
"fundingUrl": "https://www.buymeacoffee.com/fabian.schuh",
"repo": "relay-md/relay-md-obsidian-plugin",
"isDesktopOnly": false
"id": "relay-md",
"name": "Relay.md",
"version": "1.4.0",
"minAppVersion": "0.15.0",
"description": "Markdown workflows for teams.",
"author": "xeroc",
"authorUrl": "https://chainsquad.com",
"fundingUrl": "https://www.buymeacoffee.com/fabian.schuh",
"isDesktopOnly": false
}
45 changes: 24 additions & 21 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
requestUrl,
TFile,
TAbstractFile,
TFolder,
normalizePath
} from 'obsidian';

Expand Down Expand Up @@ -43,8 +44,8 @@ export default class RelayMdPLugin extends Plugin {
});

this.addCommand({
id: "relay-md-send-current-active-file",
name: "Relay.md: Send current open file",
id: "send-current-active-file",
name: "Send current open file",
callback: async () => {
new Notice("Sending document to relay.md");
const activeFile = this.app.workspace.getActiveFile();
Expand All @@ -53,25 +54,25 @@ export default class RelayMdPLugin extends Plugin {
});

this.addCommand({
id: "relay-md-fetch-documents",
name: "Relay.md: Retreive recent files",
id: "fetch-documents",
name: "Retreive recent files",
callback: async () => {
new Notice("Retreiving documents from relay.md");
await this.get_recent_documents();
}
});

// We look into all documents that are modified
this.app.vault.on('modify', (file: TAbstractFile) => {
this.registerEvent(this.app.vault.on('modify', (file: TAbstractFile) => {
if(file instanceof TFile) {
this.send_document(file);
}
});
this.app.vault.on('create', (file: TAbstractFile) => {
}));
this.registerEvent(this.app.vault.on('create', (file: TAbstractFile) => {
if(file instanceof TFile) {
this.send_document(file);
}
});
}));


// Additionally, we register a timer to fetch documents for us
Expand All @@ -95,19 +96,21 @@ export default class RelayMdPLugin extends Plugin {
}

async upsert_document(folder: string, filename: string, body: string) {
// FIXME: There is no way to check if a folder exists, so we just try create them
folder.split('/').reduce(
(directories, directory) => {
directories += `${directory}/`;
try {
this.app.vault.createFolder(directories);
} catch(e) {
// do nothing
}
return directories;
},
'',
);
// Does the folder exist? If not, create it "recusrively"
if (!(this.app.vault.getAbstractFileByPath(folder) instanceof TFolder)) {
folder.split('/').reduce(
(directories, directory) => {
directories += `${directory}/`;
try {
this.app.vault.createFolder(directories);
} catch(e) {
// do nothing
}
return directories;
},
'',
);
}
const full_path_to_file = normalizePath(folder + "/" + filename);
const fileRef = this.app.vault.getAbstractFileByPath(full_path_to_file);
if(fileRef === undefined || fileRef === null) {
Expand Down

0 comments on commit a9e7a09

Please sign in to comment.