Skip to content

Commit bb7036f

Browse files
committed
Do not assume that a node is the entire file
A roam node is no longer necessarily an entire file. It can be a file, or any heading with an id. Fixes #106
1 parent 5ecd418 commit bb7036f

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

components/Sidebar/Link.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export const PreviewLink = (props: LinkProps) => {
152152
const extraNoteStyle = outline ? outlineNoteStyle : viewerNoteStyle
153153
console.log(previewNode)
154154
const getText = () => {
155-
fetch(`http://localhost:35901/file/${file}`)
155+
fetch(`http://localhost:35901/node/${id}`)
156156
.then((res) => {
157157
return res.text()
158158
})

org-roam-ui.el

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,32 +276,33 @@ TODO: Be able to delete individual nodes."
276276
(org-roam-ui-follow-mode -1)
277277
(message "Connection with org-roam-ui closed."))
278278

279-
(defun org-roam-ui--send-text (id ws)
280-
"Send the text from org-node ID through the websocket WS."
279+
(defun org-roam-ui--get-text (id)
280+
"Retrieve the text from org-node ID."
281281
(let*
282282
((node (org-roam-populate (org-roam-node-create
283283
:id id)))
284-
(file (org-roam-node-file node))
285-
(text))
284+
(file (org-roam-node-file node)))
286285
(org-roam-with-temp-buffer
287286
file
288-
(setq text
289-
(buffer-substring-no-properties (buffer-end -1) (buffer-end 1)))
290-
text)
287+
(when (> (org-roam-node-level node) 0)
288+
;; Heading nodes have level 1 and greater.
289+
(goto-char (org-roam-node-point node))
290+
(org-narrow-to-element))
291+
(buffer-substring-no-properties (buffer-end -1) (buffer-end 1)))))
292+
293+
(defun org-roam-ui--send-text (id ws)
294+
"Send the text from org-node ID through the websocket WS."
295+
(let ((text (org-roam-ui--get-text id)))
291296
(websocket-send-text ws
292297
(json-encode
293298
`((type . "orgText")
294299
(data . ,text))))))
295300

296-
(defservlet* file/:file text/plain ()
297-
"Servlet for accessing file contents of org-roam files.
298-
299-
Just sends the complete content of org-roam files rather than the specific
300-
node, as it's much faster to do that on the UI side."
301-
(insert-file-contents-literally (org-link-decode file))
301+
(defservlet* node/:id text/plain ()
302+
"Servlet for accessing node content."
303+
(insert (org-roam-ui--get-text (org-link-decode id)))
302304
(httpd-send-header t "text/plain" 200 :Access-Control-Allow-Origin "*"))
303305

304-
305306
(defservlet* img/:file text/plain ()
306307
"Servlet for accessing images found in org-roam files."
307308
(progn

util/uniorg.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ export const UniOrg = (props: UniOrgProps) => {
3434

3535
const [previewText, setPreviewText] = useState('')
3636

37-
const file = encodeURIComponent(encodeURIComponent(previewNode.file))
37+
const id = encodeURIComponent(encodeURIComponent(previewNode.id))
3838
useEffect(() => {
39-
fetch(`http://localhost:35901/file/${file}`)
39+
fetch(`http://localhost:35901/node/${id}`)
4040
.then((res) => {
4141
return res.text()
4242
})

0 commit comments

Comments
 (0)