Skip to content

Instantly share code, notes, and snippets.

@goshatch
Created August 19, 2023 21:02
Show Gist options
  • Save goshatch/b909482f3a6cc33d6e1dffea4d93bb65 to your computer and use it in GitHub Desktop.
Save goshatch/b909482f3a6cc33d6e1dffea4d93bb65 to your computer and use it in GitHub Desktop.
Links to org-roam dailies from this day in previous years
(defun gt/org-roam-on-this-day ()
"Return a list of links to org-roam daily notes from this day in previous
years, or NIL if none are found."
(require 'org-roam)
(let* ((query "SELECT id, title FROM nodes WHERE file LIKE '%%daily%%' AND file LIKE '%%' || strftime('%%y-%%d', 'now') || '%%' ORDER BY title DESC")
(rows (org-roam-db-query query))
(result "On this day: "))
(if (null rows)
nil
(progn
(dolist (row rows)
(let* ((id (nth 0 row))
(title (nth 1 row))
(year (substring title 0 4)))
(setq result (if (string= result "On this day: ")
(format "%s[[id:%s][%s]]" result id year)
(format "%s, [[id:%s][%s]]" result id year)))))
result))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment