Skip to content

Commit

Permalink
Added tag filtering @viglioni.
Browse files Browse the repository at this point in the history
  • Loading branch information
bar authored and bar committed Jun 17, 2023
1 parent 0a3e4bb commit 689c1cb
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions org-roam-ui.el
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,28 @@ unchanged."
("FILELESS" . t))
'nil))

(defun org-roam-ui--make-graphdata ()
"Get roam data and make JSON"
(defun org-roam-ui--get-nodes-by-tags (&optional export-tags)
"Return all nodes that contain at least one tag in EXPORT-TAGS."
(if export-tags
(org-roam-db-query [:select [id
file
title
level
pos
olp
properties
(funcall group-concat tag
(emacsql-escape-raw \\\, ))]
:as tags
:from nodes
:left-join tags
:on (= id node_id)
:where (in tag $v1)
:group :by id] (vconcat export-tags))
(org-roam-ui--get-nodes)))

(defun org-roam-ui--make-graphdata (&optional export-tags)
"Get roam data and make JSON. EXPORT-TAGS are the tags to filter by."
(let* ((nodes-names
[id
file
Expand All @@ -425,7 +445,7 @@ unchanged."
(lambda (link)
(nth 1 link))
links-with-empty-refs)))
(nodes-db-rows (org-roam-ui--get-nodes))
(nodes-db-rows (org-roam-ui--get-nodes-by-tags export-tags))
(fake-nodes (seq-map #'org-roam-ui--create-fake-node empty-refs))
;; Try to update real nodes that are reference with a title build
;; from their bibliography entry. Check configuration here for avoid
Expand Down Expand Up @@ -460,9 +480,9 @@ This database model won't be supported in the future, please consider upgrading.
"Send roam data through websocket to org-roam-ui."
(websocket-send-text org-roam-ui-ws-socket (org-roam-ui--make-graphdata)))

(defun org-roam-ui--export-graphdata (file)
"Create a JSON-file containting graphdata."
(write-region (org-roam-ui--make-graphdata) nil file))
(defun org-roam-ui--export-graphdata (file &optional export-tags)
"Create a FILE in JSON format containting graphdata. Filter by EXPORT-TAGS if provided."
(write-region (org-roam-ui--make-graphdata export-tags) nil file))

(defun org-roam-ui--filter-citations (links)
"Filter out the citations from LINKS."
Expand Down Expand Up @@ -666,12 +686,15 @@ Hides . directories."

;;;###autoload
(defun org-roam-ui-export ()
"Export `org-roam-ui's-data for usage as static webserver."
(interactive)
"Export `org-roam-ui's-data for usage as static webserver.
Get only nodes that has at least one tag of EXPORT-TAGS.
If none is provided, get all nodes."
(interactive) ;; and here
(let* ((dir (read-file-name "Specify output directory:"))
(graphdata-file (concat (file-name-as-directory dir) "graphdata.json"))
(notes-dir (concat (file-name-as-directory dir) "notes/")))
(org-roam-ui--export-graphdata graphdata-file)
(export-tags (delete-dups (completing-read-multiple "Select (multiple with comma): " (org-roam-db-query [:select :distinct tag :from tags]))))
(graphdata-file (concat (file-name-as-directory dir) "graphdata.json"))
(notes-dir (concat (file-name-as-directory dir) "notes/")))
(org-roam-ui--export-graphdata graphdata-file export-tags)
(make-directory notes-dir :parents)
(mapcar (lambda (id)
(let* ((cid (car id))
Expand Down

0 comments on commit 689c1cb

Please sign in to comment.