From 7500e750d305bdc19ce878f2fa01656387f1ea52 Mon Sep 17 00:00:00 2001 From: Martin Kampas Date: Thu, 23 Jan 2025 21:25:00 +0100 Subject: [PATCH] fix: display http(s) reflinks too Consider a node with: :ROAM_REFS: http://www.example.net And another node referencing the page with a (plain) link: Lorem ipsum http://www.example.net ... With the point inside the first node, the roam buffer lists the other node under the "Reflinks" section as expected, but the roam UI does not give any clue about the relation between these two. This commit ensures that the http(s) links that have nodes with associated refs are converted to id based links of type ref, so that the UI can handle them. --- org-roam-ui.el | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/org-roam-ui.el b/org-roam-ui.el index e13349b2..45288cad 100644 --- a/org-roam-ui.el +++ b/org-roam-ui.el @@ -419,7 +419,8 @@ unchanged." 'list (org-roam-ui--separate-ref-links (org-roam-ui--get-cites)) - (org-roam-ui--get-links)))) + (org-roam-ui--separate-ref-links + (org-roam-ui--get-links))))) (links-with-empty-refs (org-roam-ui--filter-citations links-db-rows)) (empty-refs (delete-dups (seq-map (lambda (link) @@ -489,9 +490,14 @@ were in the same table as the links)." (org-roam-db-query `[:select [links:source links:dest - links:type] + links:type + refs:node-id] :from links - :where (= links:type "id")]) + :left :outer :join refs :on (= links:dest refs:ref) + :where (or + (= links:type "id") + (= links:type "http") + (= links:type "https"))]) ;; 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. @@ -509,33 +515,24 @@ were in the same table as the links)." (defun org-roam-ui--get-cites () "Get the citations when using the new db-model." (org-roam-db-query - `[:select [citations:node-id citations:cite-key refs:node-id] + `[:select [citations:node-id citations:cite-key "cite" refs:node-id] :from citations :left :outer :join refs :on (= citations:cite-key refs:ref)])) -(defun org-roam-ui--separate-ref-links (links &optional old) +(defun org-roam-ui--separate-ref-links (links) "Create separate entries for LINKS with existing reference nodes. -Optionally set OLD to t to support old citations db-model. -Convert any cite links that have nodes with associated refs to an +Convert any non-id links that have nodes with associated refs to an id based link of type `ref' while removing the 'nil `refs:node-id' from all other links." - (if (not old) - (seq-map - (lambda (link) - (pcase-let ((`(,source ,dest ,node-id) link)) - (if node-id - (list source node-id "ref") - (list source dest "cite")))) - links) - (seq-map - (lambda (link) - (pcase-let ((`(,source ,dest ,type ,node-id) link)) - (if node-id - (list source node-id "ref") - (list source dest type)))) - links))) + (seq-map + (lambda (link) + (pcase-let ((`(,source ,dest ,type ,node-id) link)) + (if node-id + (list source node-id "ref") + (list source dest type)))) + links)) (defun org-roam-ui--update-current-node () "Send the current node data to the web-socket."