Advertisement
dhniceday

LogToDailyNote

Jan 14th, 2023
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <%*
  2. const logHeader = "## Journal"
  3. const file = tp.file.find_tfile(tp.date.now("YYYY-MM-DD"))
  4. console.log('file: ' + file.name)
  5. var loggedItem = "";
  6. if (file) {
  7.     loggedItem = await tp.system.prompt("Log to daily note:","",false)
  8.     if (loggedItem !== null && loggedItem !== '') {
  9.         const time = tp.date.now("HH:mm")
  10.         const content = (await app.vault.read(file)).split("\n")
  11.         const index = content.indexOf(logHeader)
  12.            
  13.         let addContent = "- [<] " + time + " - " + loggedItem
  14.         content.splice(index + 1, 0 , addContent)
  15.         await app.vault.modify(file, content.join("\n"))
  16.     }
  17. } else {
  18.     new Notice("No daily note found.")
  19. }
  20. -%>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement