Advertisement
dhniceday

logToDailyNoteWithCategory

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