Skip to content

Instantly share code, notes, and snippets.

@wigol
Last active June 3, 2024 09:38
Show Gist options
  • Save wigol/83aa97098543787b4218849d327ec48c to your computer and use it in GitHub Desktop.
Save wigol/83aa97098543787b4218849d327ec48c to your computer and use it in GitHub Desktop.
org-roam dailies report
(defun wg/build-roam-journal ()
(interactive)
(let ((journal_files (org-roam-db-query [:select [title, file] :from nodes :where (like file "%/journals/%") :order-by [(asc file)]])))
(with-output-to-temp-buffer "*eng-journal-export*"
(pop-to-buffer "*eng-journal-export*")
(org-mode)
(erase-buffer)
(insert (format "#+title: Engineering Journal\n#+date: %s\n#+options: broken-links:t toc:nil num:nil\n" (format-time-string "%Y-%m-%d")))
(dolist (jfile journal_files)
(insert (format "* %s\n" (car jfile) ))
(let ((orgbuf (get-file-buffer (nth 1 jfile)))
(orgst nil)
orgcont
pastestart
pasteend)
(when (not orgbuf)
(setq orgbuf (find-file-noselect (nth 1 jfile))))
(save-excursion
(set-buffer orgbuf)
(setq orgst (org-element-parse-buffer))
(goto-char 1)
(org-forward-heading-same-level 0) ;; skip metadata
(setq orgcont (buffer-substring (point) (point-max))))
(setq pastestart (point))
(insert (format "%s\n" orgcont))
(setq pastestop (point))
;; we now need to demote all the pasted headings, so they could
;; work well with the dates.
(save-excursion
(push-mark pastestart)
(goto-char pastestop)
(setq mark-active t)
(org-do-demote)
(deactivate-mark))
)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment