mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(fix): keep id backlinks on filename change (#1367)
This commit is contained in:
18
org-roam.el
18
org-roam.el
@ -1422,6 +1422,14 @@ When NEW-FILE-OR-DIR is a directory, we use it to compute the new file path."
|
|||||||
old-file))
|
old-file))
|
||||||
;; Remove database entries for old-file.org
|
;; Remove database entries for old-file.org
|
||||||
(org-roam-db--clear-file old-file)
|
(org-roam-db--clear-file old-file)
|
||||||
|
;; If the new path is in a different directory, relative links
|
||||||
|
;; will break. Fix all file-relative links:
|
||||||
|
(unless (string= (file-name-directory old-file)
|
||||||
|
(file-name-directory new-file))
|
||||||
|
(org-roam-with-file new-file nil
|
||||||
|
(org-roam--fix-relative-links old-file)))
|
||||||
|
(when (org-roam--org-roam-file-p new-file)
|
||||||
|
(org-roam-db--update-file new-file))
|
||||||
;; Replace links from old-file.org -> new-file.org in all Org-roam files with these links
|
;; Replace links from old-file.org -> new-file.org in all Org-roam files with these links
|
||||||
(mapc (lambda (file)
|
(mapc (lambda (file)
|
||||||
(setq file (if (string-equal (car file) old-file)
|
(setq file (if (string-equal (car file) old-file)
|
||||||
@ -1431,15 +1439,7 @@ When NEW-FILE-OR-DIR is a directory, we use it to compute the new file path."
|
|||||||
(org-roam--replace-link old-file new-file)
|
(org-roam--replace-link old-file new-file)
|
||||||
(save-buffer)
|
(save-buffer)
|
||||||
(org-roam-db--update-file)))
|
(org-roam-db--update-file)))
|
||||||
files-affected)
|
files-affected))))
|
||||||
;; If the new path is in a different directory, relative links
|
|
||||||
;; will break. Fix all file-relative links:
|
|
||||||
(unless (string= (file-name-directory old-file)
|
|
||||||
(file-name-directory new-file))
|
|
||||||
(org-roam-with-file new-file nil
|
|
||||||
(org-roam--fix-relative-links old-file)))
|
|
||||||
(when (org-roam--org-roam-file-p new-file)
|
|
||||||
(org-roam-db--update-file new-file)))))
|
|
||||||
|
|
||||||
(defun org-roam--id-new-advice (&rest _args)
|
(defun org-roam--id-new-advice (&rest _args)
|
||||||
"Update the database if a new Org ID is created."
|
"Update the database if a new Org ID is created."
|
||||||
|
Reference in New Issue
Block a user