diff options
author | Thomas F. K. Jorna <[email protected]> | 2021-08-02 14:08:13 +0200 |
---|---|---|
committer | Thomas F. K. Jorna <[email protected]> | 2021-08-02 14:08:13 +0200 |
commit | 66dc7f3477ee250e8fb4a66902d2f2423df84664 (patch) | |
tree | a48d9a649afbdbfe1d403dc2bb61b7520481d095 /org-roam-ui.el | |
parent | b684e5dd7f076f54bc041e96f21ced754a4e7432 (diff) | |
parent | ab3ec40a1ea8a21eb7a0468f841ad617e0b0155b (diff) |
build: citelinks
Diffstat (limited to 'org-roam-ui.el')
-rw-r--r-- | org-roam-ui.el | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/org-roam-ui.el b/org-roam-ui.el index 17952c8..098e99e 100644 --- a/org-roam-ui.el +++ b/org-roam-ui.el @@ -159,10 +159,24 @@ This serves the web-build and API over HTTP." (defun org-roam-ui--send-graphdata () "Get roam data, make JSON, send through websocket to org-roam-ui." - (let* ((nodes-columns [id file title level]) - (links-columns [source dest type]) + (let* ((nodes-columns [id file title level properties]) + (links-columns [links:source links:dest links:type refs:node-id]) (nodes-db-rows (org-roam-db-query `[:select ,nodes-columns :from nodes])) - (links-db-rows (org-roam-db-query `[:select ,links-columns :from links :where (or (= type "id") (= type "cite"))])) + ;; Left outer join on refs means any id link (or cite link without a + ;; corresponding node) will have 'nil for the `refs:node-id' value. Any + ;; cite link where a node has that `:ROAM_REFS:' will have a value. + (links-db-rows (org-roam-db-query `[:select ,links-columns + :from links + :left :outer :join refs :on (= links:dest refs:ref) + :where (or (= links:type "id") (= links:type "cite"))])) + ;; Convert any cite links that have nodes with associated refs to a + ;; standard id link while removing the 'nil `refs:node-id' from all + ;; other links + (links-db-rows (seq-map (lambda (l) + (pcase-let ((`(,source ,dest ,type ,node-id) l)) + (if node-id + (list source node-id "cite") + (list source dest type)))) links-db-rows)) (response `((nodes . ,(mapcar (apply-partially #'org-roam-ui-sql-to-alist (append nodes-columns nil)) nodes-db-rows)) (links . ,(mapcar (apply-partially #'org-roam-ui-sql-to-alist '(source target type)) links-db-rows))))) (websocket-send-text oru-ws (json-encode `((type . "graphdata") (data . ,response)))))) |