summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorGravatar Tom Willemse2024-06-08 15:45:46 -0700
committerGravatar Tom Willemse2024-06-08 15:45:46 -0700
commit6fcf17760aeb8a16005b12dfe219edf106d736e1 (patch)
treef43c5af25cdd901701ba15646a563ea1d5d22fa0
parent9a76f16d3fdd49a1733e5f2777036f1f83068a40 (diff)
parent96d383d8c2d6c8cd310eea89b5c200e5c2c502d5 (diff)
downloadnroam-6fcf17760aeb8a16005b12dfe219edf106d736e1.tar.gz
nroam-6fcf17760aeb8a16005b12dfe219edf106d736e1.zip
Merge branch 'org-roam-v2' into oni
-rw-r--r--nroam-backlinks.el29
-rw-r--r--nroam-utils.el5
2 files changed, 18 insertions, 16 deletions
diff --git a/nroam-backlinks.el b/nroam-backlinks.el
index f4ee29e..0e8c06b 100644
--- a/nroam-backlinks.el
+++ b/nroam-backlinks.el
@@ -47,13 +47,18 @@
(defun nroam-backlinks--get-backlinks ()
"Return a list of backlinks for the current buffer."
- (if-let* ((file-path (buffer-file-name (current-buffer)))
- (titles (org-roam--extract-titles)))
- (org-roam--get-backlinks (cons file-path titles))))
+ (save-excursion
+ (goto-char (point-min))
+ (let ((node (org-roam-node-at-point)))
+ (seq-remove (lambda (b)
+ (string= (org-roam-node-file (org-roam-backlink-source-node b))
+ (org-roam-node-file node)))
+ (org-roam-backlinks-get node)))))
(defun nroam-backlinks--group (backlinks)
"Return BACKLINKS grouped by source file."
- (seq-group-by #'car backlinks))
+ (seq-group-by (lambda (l) (org-roam-node-file (org-roam-backlink-source-node l)))
+ backlinks))
(defun nroam-backlinks--insert-heading (count)
"Insert the heading for the backlinks section with a COUNT."
@@ -66,19 +71,21 @@
"Insert all backlinks in GROUP."
(let* ((file (car group))
(backlinks (cdr group))
- (title (org-roam-format-link file
- (org-roam-db--get-title file)
- "file")))
+ (title (org-link-make-string (concat "file:" file)
+ (caar (org-roam-db-query
+ [:select title :from nodes :where (= file $s1)]
+ file)))))
(nroam--insert-heading 3 title)
(nroam--do-separated-by-newlines #'nroam-backlinks--insert-backlink backlinks)))
(defun nroam-backlinks--insert-backlink (backlink)
"Insert the source element where BACKLINK is defined."
- (seq-let (file _ props) backlink
- (when-let* ((point (plist-get props :point))
- (elt (nroam-backlinks--crawl-source file point))
+ (let* ((backlink-node (org-roam-backlink-source-node backlink))
+ (file (org-roam-node-file backlink-node))
+ (point (org-roam-backlink-point backlink)))
+ (when-let* ((elt (nroam-backlinks--crawl-source file point))
(type (plist-get elt :type))
- (content (nroam--fix-links (string-trim (plist-get elt :string)) file))
+ (content (org-roam-preview-get-contents file point))
(beg (point)))
(let ((outline (plist-get elt :outline))
(full-outline (plist-get elt :full-outline)))
diff --git a/nroam-utils.el b/nroam-utils.el
index 737691b..a3154fe 100644
--- a/nroam-utils.el
+++ b/nroam-utils.el
@@ -55,10 +55,5 @@ Insert a single newline between each call to FUNCTION."
(funcall function item))
sequence))
-(defun nroam--fix-links (content origin)
- "Correct all relative links in CONTENT from ORIGIN.
-Temporary fix until `org-roam' v2 is out."
- (org-roam-buffer-expand-links content origin))
-
(provide 'nroam-utils)
;;; nroam-utils.el ends here