Created
March 7, 2021 04:27
-
-
Save skoji/50052b18220fe8a9b45cf4626397e722 to your computer and use it in GitHub Desktop.
Daily Journal script for Inkdrop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inkdrop.commands.add(document.body, "custom:new-journal", async () => { | |
const db = inkdrop.main.dataStore.getLocalDB() | |
const bookId = (await db.books.findWithName('Journal'))._id | |
const title = `Daily: ${new Date().toLocaleDateString()}` | |
const existingNotes = (await db.notes.findInBook(bookId)).docs.filter(f => f.title === title) | |
if (existingNotes.length > 0) { | |
inkdrop.commands.dispatch(document.body, "core:open-note", { | |
noteId: existingNotes[0]._id | |
}); | |
return; | |
} | |
const note = { | |
body: '', | |
bookId: bookId, | |
doctype: 'markdown', | |
_id: db.notes.createId(), | |
_rev: undefined, | |
title: title, | |
createdAt: +new Date(), | |
updatedAt: +new Date(), | |
pinned: false, | |
} | |
try { | |
await db.notes.put(note) | |
inkdrop.commands.dispatch(document.body, "core:open-note", { | |
noteId: note._id, | |
}) | |
inkdrop.commands.dispatch(document.body, "editor:focus-mde") | |
} catch (e) { | |
console.error(e) | |
} | |
}) | |
inkdrop.menu.add([ | |
{ | |
label: "File", | |
submenu: [ | |
{ | |
label: "Daily Journal", | |
command: "custom:new-journal", | |
}, | |
], | |
}, | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment