Skip to content

Instantly share code, notes, and snippets.

@skoji
Created March 7, 2021 04:27
Show Gist options
  • Save skoji/50052b18220fe8a9b45cf4626397e722 to your computer and use it in GitHub Desktop.
Save skoji/50052b18220fe8a9b45cf4626397e722 to your computer and use it in GitHub Desktop.
Daily Journal script for Inkdrop
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