(fix): fix link expansion on URL links (#1103)

Attempting to perform link expansion on URL links caused extreme slowdowns in Windows environment. Ref #1038 #1067.

Co-authored-by: Noboru Ota <me@nobiot.com>
This commit is contained in:
Jethro Kuan
2020-09-17 13:28:42 +08:00
committed by GitHub
parent e881ea26b1
commit 8ec4cafa2b
2 changed files with 17 additions and 11 deletions

View File

@ -25,6 +25,7 @@ In this release we support fuzzy links of the form `[[Title]]`, `[[*Headline]]`
### Bugfixes
- [#1057](https://github.com/org-roam/org-roam/pull/1057) Improve performance of database builds by preventing generation of LaTeX and image previews.
- [#1103](https://github.com/org-roam/org-roam/pull/1103) Fix long build-times for Windows on files with URL links
## 1.2.1 (27-07-2020)

View File

@ -335,6 +335,12 @@ function are expected to catch the error."
(t
(signal 'wrong-type-argument `((stringp numberp symbolp) ,item))))) items))))
(defun org-roam--url-p (path)
"Check if PATH is a URL.
Assume the protocol is not present in PATH; e.g. URL `https://google.com' is
passed as `//google.com'."
(string-prefix-p "//" path))
;;;; File functions and predicates
(defun org-roam--file-name-extension (filename)
"Return file name extension for FILENAME.
@ -525,21 +531,19 @@ The search terminates when the first property is encountered."
"Crawl CONTENT for relative links and expand them.
PATH should be the root from which to compute the relativity."
(let ((dir (file-name-directory path))
link link-type)
link)
(with-temp-buffer
(insert content)
(goto-char (point-min))
;; Loop over links
(while (re-search-forward org-roam--org-link-bracket-typed-re (point-max) t)
(setq link (match-string 2))
(when (f-relative-p link)
(save-excursion
(goto-char (match-beginning 2))
(setq link-type (match-string 1)
link (match-string 2))
;; Delete relative link
(when (and (member link-type '("file")) ; TODO: Fix this
(f-relative-p link))
(delete-region (match-beginning 2)
(match-end 2))
(insert (expand-file-name link dir))))
(insert (expand-file-name link dir)))))
(buffer-string))))
(defun org-roam--get-outline-path ()
@ -623,7 +627,8 @@ it as FILE-PATH."
(setq type "cite")
(org-ref-split-and-strip-string path))
("fuzzy" (list path))
(_ (if (file-remote-p path)
(_ (if (or (file-remote-p path)
(org-roam--url-p path))
(list path)
(let ((file-maybe (file-truename
(expand-file-name path (file-name-directory file-path)))))