summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--components/Sidebar/Link.tsx2
-rw-r--r--org-roam-ui.el29
-rw-r--r--util/uniorg.tsx4
3 files changed, 18 insertions, 17 deletions
diff --git a/components/Sidebar/Link.tsx b/components/Sidebar/Link.tsx
index e5b1102..6130eb5 100644
--- a/components/Sidebar/Link.tsx
+++ b/components/Sidebar/Link.tsx
@@ -152,7 +152,7 @@ export const PreviewLink = (props: LinkProps) => {
const extraNoteStyle = outline ? outlineNoteStyle : viewerNoteStyle
console.log(previewNode)
const getText = () => {
- fetch(`http://localhost:35901/file/${file}`)
+ fetch(`http://localhost:35901/node/${id}`)
.then((res) => {
return res.text()
})
diff --git a/org-roam-ui.el b/org-roam-ui.el
index 165e5ed..f95245a 100644
--- a/org-roam-ui.el
+++ b/org-roam-ui.el
@@ -276,32 +276,33 @@ TODO: Be able to delete individual nodes."
(org-roam-ui-follow-mode -1)
(message "Connection with org-roam-ui closed."))
-(defun org-roam-ui--send-text (id ws)
- "Send the text from org-node ID through the websocket WS."
+(defun org-roam-ui--get-text (id)
+ "Retrieve the text from org-node ID."
(let*
((node (org-roam-populate (org-roam-node-create
:id id)))
- (file (org-roam-node-file node))
- (text))
+ (file (org-roam-node-file node)))
(org-roam-with-temp-buffer
file
- (setq text
- (buffer-substring-no-properties (buffer-end -1) (buffer-end 1)))
- text)
+ (when (> (org-roam-node-level node) 0)
+ ;; Heading nodes have level 1 and greater.
+ (goto-char (org-roam-node-point node))
+ (org-narrow-to-element))
+ (buffer-substring-no-properties (buffer-end -1) (buffer-end 1)))))
+
+(defun org-roam-ui--send-text (id ws)
+ "Send the text from org-node ID through the websocket WS."
+ (let ((text (org-roam-ui--get-text id)))
(websocket-send-text ws
(json-encode
`((type . "orgText")
(data . ,text))))))
-(defservlet* file/:file text/plain ()
- "Servlet for accessing file contents of org-roam files.
-
-Just sends the complete content of org-roam files rather than the specific
-node, as it's much faster to do that on the UI side."
- (insert-file-contents-literally (org-link-decode file))
+(defservlet* node/:id text/plain ()
+ "Servlet for accessing node content."
+ (insert (org-roam-ui--get-text (org-link-decode id)))
(httpd-send-header t "text/plain" 200 :Access-Control-Allow-Origin "*"))
-
(defservlet* img/:file text/plain ()
"Servlet for accessing images found in org-roam files."
(progn
diff --git a/util/uniorg.tsx b/util/uniorg.tsx
index c4407f2..6580b9c 100644
--- a/util/uniorg.tsx
+++ b/util/uniorg.tsx
@@ -34,9 +34,9 @@ export const UniOrg = (props: UniOrgProps) => {
const [previewText, setPreviewText] = useState('')
- const file = encodeURIComponent(encodeURIComponent(previewNode.file))
+ const id = encodeURIComponent(encodeURIComponent(previewNode.id))
useEffect(() => {
- fetch(`http://localhost:35901/file/${file}`)
+ fetch(`http://localhost:35901/node/${id}`)
.then((res) => {
return res.text()
})