summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas F. K. Jorna <[email protected]>2021-12-04 13:44:47 +0100
committerGitHub <[email protected]>2021-12-04 13:44:47 +0100
commit0062fc08917e9ee70148105fe5134e9f4dcf9aba (patch)
tree43cae6d205afd8fdf4f9e70e93eeecf50b2bc109
parent4edbd2abae11def87284d6f7a4a2e1fd4e122cd6 (diff)
fix: add org-attach-id-dir support (#153)
-rw-r--r--components/Sidebar/Backlinks.tsx5
-rw-r--r--components/Sidebar/Link.tsx6
-rw-r--r--components/Sidebar/Note.tsx5
-rw-r--r--components/Sidebar/index.tsx3
-rw-r--r--org-roam-ui.el5
-rw-r--r--pages/index.tsx2
-rw-r--r--util/processOrg.tsx10
-rw-r--r--util/uniorg.tsx5
8 files changed, 37 insertions, 4 deletions
diff --git a/components/Sidebar/Backlinks.tsx b/components/Sidebar/Backlinks.tsx
index 892af8c..9bfb1fe 100644
--- a/components/Sidebar/Backlinks.tsx
+++ b/components/Sidebar/Backlinks.tsx
@@ -16,6 +16,8 @@ export interface BacklinksProps {
setSidebarHighlightedNode: OrgRoamNode
openContextMenu: any
outline: boolean
+ attachDir: string
+ macros: { [key: string]: string }
}
import { PreviewLink } from './Link'
@@ -32,6 +34,8 @@ export const Backlinks = (props: BacklinksProps) => {
nodeByCite,
openContextMenu,
outline,
+ macros,
+ attachDir,
} = props
const links = linksByNodeId[previewNode?.id] ?? []
@@ -69,6 +73,7 @@ export const Backlinks = (props: BacklinksProps) => {
openContextMenu={openContextMenu}
outline={outline}
noUnderline
+ {...{ attachDir, macros }}
>
{nodeById[link as string]?.title}
</PreviewLink>
diff --git a/components/Sidebar/Link.tsx b/components/Sidebar/Link.tsx
index c4eea2f..e5b1102 100644
--- a/components/Sidebar/Link.tsx
+++ b/components/Sidebar/Link.tsx
@@ -41,6 +41,8 @@ export interface LinkProps {
linksByNodeId: LinksByNodeId
isWiki?: boolean
noUnderline?: boolean
+ attachDir: string
+ macros: { [key: string]: string }
}
export interface NodeLinkProps {
@@ -138,6 +140,8 @@ export const PreviewLink = (props: LinkProps) => {
noUnderline,
linksByNodeId,
isWiki,
+ macros,
+ attachDir,
} = props
// TODO figure out how to properly type this
// see https://github.com/rehypejs/rehype-react/issues/25
@@ -290,6 +294,8 @@ export const PreviewLink = (props: LinkProps) => {
openContextMenu,
outline,
linksByNodeId,
+ macros,
+ attachDir,
}}
previewNode={nodeById[id]!}
collapse={false}
diff --git a/components/Sidebar/Note.tsx b/components/Sidebar/Note.tsx
index 1f864f3..2b76994 100644
--- a/components/Sidebar/Note.tsx
+++ b/components/Sidebar/Note.tsx
@@ -21,6 +21,7 @@ export interface NoteProps {
outline: boolean
collapse: boolean
macros?: { [key: string]: string }
+ attachDir: string
}
export const Note = (props: NoteProps) => {
@@ -37,6 +38,7 @@ export const Note = (props: NoteProps) => {
outline,
collapse,
macros,
+ attachDir,
} = props
const extraStyle = outline ? outlineNoteStyle : viewerNoteStyle
@@ -71,6 +73,7 @@ export const Note = (props: NoteProps) => {
nodeById,
linksByNodeId,
macros,
+ attachDir,
}}
/>
<Backlinks
@@ -83,7 +86,9 @@ export const Note = (props: NoteProps) => {
setSidebarHighlightedNode,
openContextMenu,
outline,
+ attachDir,
}}
+ macros={macros || {}}
/>
</Flex>
)}
diff --git a/components/Sidebar/index.tsx b/components/Sidebar/index.tsx
index c23d938..66728fd 100644
--- a/components/Sidebar/index.tsx
+++ b/components/Sidebar/index.tsx
@@ -50,6 +50,7 @@ export interface SidebarProps {
tagColors: TagColors
setTagColors: any
macros?: { [key: string]: string }
+ attachDir: string
}
const Sidebar = (props: SidebarProps) => {
@@ -77,6 +78,7 @@ const Sidebar = (props: SidebarProps) => {
tagColors,
setTagColors,
macros,
+ attachDir,
} = props
const { highlightColor } = useContext(ThemeContext)
@@ -228,6 +230,7 @@ const Sidebar = (props: SidebarProps) => {
setOutline,
collapse,
macros,
+ attachDir,
}}
/>
</VStack>
diff --git a/org-roam-ui.el b/org-roam-ui.el
index 17059fe..83a5382 100644
--- a/org-roam-ui.el
+++ b/org-roam-ui.el
@@ -577,13 +577,16 @@ from all other links."
(expand-file-name org-roam-dailies-directory)
(expand-file-name
org-roam-dailies-directory
- org-roam-directory))))
+ org-roam-directory)))
+ (attach-dir (if (boundp 'org-attach-id-dir) org-attach-id-dir (expand-file-name ".attach/" org-directory))))
(websocket-send-text ws
(json-encode
`((type . "variables")
(data .
(("dailyDir" .
,daily-dir)
+ ("attachDir" .
+ ,attach-dir)
("roamDir" . ,org-roam-directory)
("katexMacros" . ,org-roam-ui-latex-macros)))))))))
diff --git a/pages/index.tsx b/pages/index.tsx
index c74f0af..cf54e92 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -77,6 +77,7 @@ export interface EmacsVariables {
roamDir?: string
dailyDir?: string
katexMacros?: { [key: string]: string }
+ attachDir?: string
}
export type Tags = string[]
export type Scope = {
@@ -672,6 +673,7 @@ export function GraphPage() {
setFilter,
}}
macros={variablesRef.current.katexMacros}
+ attachDir={variablesRef.current.attachDir || ''}
nodeById={nodeByIdRef.current!}
linksByNodeId={linksByNodeIdRef.current!}
nodeByCite={nodeByCiteRef.current!}
diff --git a/util/processOrg.tsx b/util/processOrg.tsx
index 189e980..e139c41 100644
--- a/util/processOrg.tsx
+++ b/util/processOrg.tsx
@@ -44,7 +44,8 @@ export interface ProcessedOrgProps {
outline: boolean
collapse: boolean
linksByNodeId: LinksByNodeId
- macros?: { [key: string]: string }
+ macros: { [key: string]: string } | {}
+ attachDir: string
}
export const ProcessedOrg = (props: ProcessedOrgProps) => {
@@ -60,6 +61,7 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
collapse,
linksByNodeId,
macros,
+ attachDir,
} = props
if (!previewNode || !linksByNodeId) {
return null
@@ -68,7 +70,9 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
const orgProcessor = unified()
.use(uniorgParse)
.use(extractKeywords)
- .use(attachments)
+ .use(attachments, {
+ idDir: attachDir || undefined,
+ })
.use(uniorgSlug)
.use(uniorg2rehype, { useSections: true })
@@ -146,6 +150,8 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
outline={outline}
previewNode={previewNode}
isWiki={isMarkdown}
+ macros={macros}
+ attachDir={attachDir}
>
{children}
</PreviewLink>
diff --git a/util/uniorg.tsx b/util/uniorg.tsx
index 68f0330..c4407f2 100644
--- a/util/uniorg.tsx
+++ b/util/uniorg.tsx
@@ -14,6 +14,7 @@ export interface UniOrgProps {
collapse: boolean
linksByNodeId: LinksByNodeId
macros?: { [key: string]: string }
+ attachDir: string
}
export const UniOrg = (props: UniOrgProps) => {
@@ -28,6 +29,7 @@ export const UniOrg = (props: UniOrgProps) => {
collapse,
linksByNodeId,
macros,
+ attachDir,
} = props
const [previewText, setPreviewText] = useState('')
@@ -69,8 +71,9 @@ export const UniOrg = (props: UniOrgProps) => {
outline,
collapse,
linksByNodeId,
- macros,
+ attachDir,
}}
+ macros={macros || {}}
/>
)}
</>