Skip to content

Commit

Permalink
Merge pull request #13 from RobertoGoAm/create-drafts-in-vault-root
Browse files Browse the repository at this point in the history
Looks great, thanks!
  • Loading branch information
ryanjamurphy committed Nov 7, 2022
2 parents 1418da5 + b87319f commit 199af45
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions main.ts
Expand Up @@ -229,17 +229,20 @@ ${this.settings.logPrefix}${tampTime}`
async timber() {

let zkUUIDNoteName = moment().format(this.settings.newDraftFilenameTemplate);
const isInboxPathEmpty = this.settings.inboxFilePath === undefined || this.settings.inboxFilePath.trim() === '';
const folderName = isInboxPathEmpty ? '' : this.settings.inboxFilePath;
const inboxPath = isInboxPathEmpty ? '' : `/${this.settings.inboxFilePath}/`;

console.debug(`${this.settings.inboxFilePath}`);

if (!(this.app.vault.getAbstractFileByPath(`${this.settings.inboxFilePath}`))) { // In the future, handle folder creation as necessary. For now, error and tell the user if the inbox folder does not exist.
if (!isInboxPathEmpty && !(this.app.vault.getAbstractFileByPath(`${folderName}`))) { // In the future, handle folder creation as necessary. For now, error and tell the user if the inbox folder does not exist.
new Notice(`Error. Lumberjack couldn't create the draft. Does the inbox folder you've set in Preferences -> Lumberjack 🪓🪵 exist?`);
return;
}

await this.app.vault.create(`/${this.settings.inboxFilePath}/${zkUUIDNoteName}.md`, "");
await this.app.vault.create(`${inboxPath}${zkUUIDNoteName}.md`, "");

let newDraft = await this.app.workspace.openLinkText(zkUUIDNoteName, `/${this.settings.inboxFilePath}/`, this.settings.alwaysOpenInNewLeaf, editModeState);
let newDraft = await this.app.workspace.openLinkText(zkUUIDNoteName, `${inboxPath}`, this.settings.alwaysOpenInNewLeaf, editModeState);

if (this.app.workspace.getActiveViewOfType(MarkdownView)) {
let editor = this.app.workspace.getActiveViewOfType(MarkdownView).editor;
Expand Down

0 comments on commit 199af45

Please sign in to comment.