UP | HOME

Reading List

Table of Contents

1. To Read

2. Currently Reading

3. Yearly History

4. Code

Generate the list of books currently being read (tag "Reading"):

(mapconcat
 (lambda (node)
   (princ (format "- [[file:%s][%s]]"
                  (org-roam-node-file (org-roam-node-from-id (nth 0 node)))
                  (nth 1 node))))
 (org-roam-db-query
  [:select [nodes:id nodes:title]
           :from nodes
           :inner :join tags
           :on (= nodes:id tags:node_id)
           :where (= tags:tag "Reading")])
 "\n")

Generate a by-year list of each book that is marked with tag "Read":

(let ((year-map (make-hash-table :test 'equal)))
  (dolist (result (org-roam-db-query
                   [:select [nodes:id nodes:title files:mtime]
                            :from nodes
                            :inner :join files
                            :on (= nodes:file files:file)
                            :inner :join tags
                            :on (= nodes:id tags:node_id)
                            :where (= tags:tag "Read")]))
    (let* ((id (nth 0 result))
           (title (nth 1 result))
           (year (format-time-string "%Y" (nth 2 result)))
           (file (org-roam-node-file (org-roam-node-from-id id)))
           (rel-file (file-relative-name file (file-name-directory buffer-file-name)))
           (html-file (concat (file-name-sans-extension rel-file) ".html"))
           (entry (format "  - [[file:%s][%s]]" html-file title)))
      (push entry (gethash year year-map))))

  (maphash (lambda (year entries)
             (princ (format "*** %s\n%s\n"
                             year
                             (mapconcat #'identity (nreverse entries) "\n"))))
           year-map))

Author: Aaron Bieber

Created: 2025-08-07 Thu 11:37

Validate