Skip to content

Commit 5a93993

Browse files
authored
Merge pull request #208 from org-roam/fix/106
2 parents f1e1769 + 7da9813 commit 5a93993

File tree

10 files changed

+6730
-35
lines changed

10 files changed

+6730
-35
lines changed

.github/workflows/cd.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ jobs:
4949
git config --global url."https://github.com/".insteadOf ssh://[email protected]/
5050
git config --global url."https://".insteadOf git://
5151
git config --global url."https://".insteadOf ssh://
52-
npm install
53-
npm run build
54-
npm run export
52+
yarn install
53+
yarn run build
54+
yarn run export
5555
- name: '[Add GitHub Sponsors to Readme]'
5656
uses: JamesIves/[email protected]
5757
with:

.github/workflows/ci.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
branches:
88
- '**'
99
- '!main'
10+
workflow_dispatch:
1011
defaults:
1112
run:
1213
shell: 'bash'
@@ -51,8 +52,8 @@ jobs:
5152
git config --global url."https://github.com/".insteadOf ssh://[email protected]/
5253
git config --global url."https://".insteadOf git://
5354
git config --global url."https://".insteadOf ssh://
54-
npm install
55-
npm run build
56-
npm run export
55+
yarn install
56+
yarn run build
57+
yarn run export
5758
...
5859
# End of ci.yml

components/Sidebar/Backlinks.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import React from 'react'
88
import { ProcessedOrg } from '../../util/processOrg'
99

1010
export interface BacklinksProps {
11-
previewNode: any
11+
previewNode: NodeObject | OrgRoamNode
1212
setPreviewNode: any
1313
nodeById: NodeById
1414
linksByNodeId: LinksByNodeId
@@ -37,7 +37,7 @@ export const Backlinks = (props: BacklinksProps) => {
3737
macros,
3838
attachDir,
3939
} = props
40-
const links = linksByNodeId[previewNode?.id] ?? []
40+
const links = linksByNodeId[(previewNode as OrgRoamNode)?.id] ?? []
4141

4242
const backLinks = links
4343
.filter((link: LinkObject) => {

components/Sidebar/Link.tsx

+1-1
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

+15-14
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

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"es6-tween": "^5.5.11",
2929
"framer-motion": "^4",
3030
"hast-to-hyperscript": "^9.0.1",
31+
"hast-util-to-string": "1",
3132
"hastscript": "^6.0.0",
3233
"jlouvain.js": "^1.0.0",
3334
"next": "^11.1.0",

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"moduleResolution": "node",
1313
"resolveJsonModule": true,
1414
"isolatedModules": true,
15-
"jsx": "preserve"
15+
"jsx": "preserve",
16+
"incremental": true
1617
},
1718
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
1819
"exclude": ["node_modules"]

util/processOrg.tsx

+17-9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ import { Section } from '../components/Sidebar/Section'
3333
import { NoteContext } from './NoteContext'
3434
import { OrgRoamLink, OrgRoamNode } from '../api'
3535

36+
// @ts-expect-error non-ESM unified means no types
37+
import { toString } from 'hast-util-to-string'
38+
import { Box } from '@chakra-ui/react'
39+
3640
export interface ProcessedOrgProps {
3741
nodeById: NodeById
3842
previewNode: OrgRoamNode
@@ -63,6 +67,7 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
6367
macros,
6468
attachDir,
6569
} = props
70+
6671
if (!previewNode || !linksByNodeId) {
6772
return null
6873
}
@@ -96,7 +101,6 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
96101
}
97102

98103
const wikiLinkProcessor = (wikiLink: string): string => {
99-
console.log(wikiLink)
100104
return `id:${wikiLink}`
101105
}
102106

@@ -160,11 +164,18 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
160164
img: ({ src }) => {
161165
return <OrgImage src={src as string} file={previewNode?.file} />
162166
},
163-
section: ({ children, className }) => (
164-
<Section {...{ outline, collapse }} className={className as string}>
165-
{children}
166-
</Section>
167-
),
167+
section: ({ children, className }) => {
168+
console.log(className)
169+
console.log(previewNode.level)
170+
if (className && (className as string).slice(-1) === `${previewNode.level}`) {
171+
return <Box>{(children as React.ReactElement[]).slice(1)}</Box>
172+
}
173+
return (
174+
<Section {...{ outline, collapse }} className={className as string}>
175+
{children}
176+
</Section>
177+
)
178+
},
168179
p: ({ children }) => {
169180
return <p lang="en">{children as ReactNode}</p>
170181
},
@@ -178,6 +189,3 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
178189
<NoteContext.Provider value={{ collapse, outline }}>{text as ReactNode}</NoteContext.Provider>
179190
)
180191
}
181-
function useCallBack(arg0: () => unified.Processor<unified.Settings>) {
182-
throw new Error('Function not implemented.')
183-
}

util/uniorg.tsx

+2-2
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)