From 94b543c1d28743f85bee2342609ff2019f7ec7d8 Mon Sep 17 00:00:00 2001
From: Huynh Tan <danhuynhdev@gmail.com>
Date: Wed, 29 Jun 2022 14:25:40 +0700
Subject: Making sure attachment preview works with file level ID

---
 util/processOrg.tsx | 1 +
 1 file changed, 1 insertion(+)

(limited to 'util/processOrg.tsx')

diff --git a/util/processOrg.tsx b/util/processOrg.tsx
index fa135a1..611c039 100644
--- a/util/processOrg.tsx
+++ b/util/processOrg.tsx
@@ -77,6 +77,7 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
     .use(extractKeywords)
     .use(attachments, {
       idDir: attachDir || undefined,
+      useInheritance: true,
     })
     .use(uniorgSlug)
     .use(uniorg2rehype, { useSections: true })
-- 
cgit v1.2.3


From 11111bb49889feb1b00e6814d9d81e3e23409d7c Mon Sep 17 00:00:00 2001
From: Huynh Tan <danhuynhdev@gmail.com>
Date: Thu, 30 Jun 2022 15:52:03 +0700
Subject: Read useInheritance from emacs config

---
 components/Sidebar/Backlinks.tsx | 4 +++-
 components/Sidebar/Link.tsx      | 3 +++
 components/Sidebar/Note.tsx      | 4 ++++
 components/Sidebar/index.tsx     | 3 +++
 org-roam-ui.el                   | 5 +++++
 pages/index.tsx                  | 2 ++
 util/processOrg.tsx              | 5 ++++-
 util/uniorg.tsx                  | 3 +++
 util/variablesContext.tsx        | 1 +
 9 files changed, 28 insertions(+), 2 deletions(-)

(limited to 'util/processOrg.tsx')

diff --git a/components/Sidebar/Backlinks.tsx b/components/Sidebar/Backlinks.tsx
index 6a5dd00..0bbf415 100644
--- a/components/Sidebar/Backlinks.tsx
+++ b/components/Sidebar/Backlinks.tsx
@@ -17,6 +17,7 @@ export interface BacklinksProps {
   openContextMenu: any
   outline: boolean
   attachDir: string
+  useInheritance: boolean
   macros: { [key: string]: string }
 }
 
@@ -36,6 +37,7 @@ export const Backlinks = (props: BacklinksProps) => {
     outline,
     macros,
     attachDir,
+    useInheritance,
   } = props
   const links = linksByNodeId[(previewNode as OrgRoamNode)?.id] ?? []
 
@@ -73,7 +75,7 @@ export const Backlinks = (props: BacklinksProps) => {
                   openContextMenu={openContextMenu}
                   outline={outline}
                   noUnderline
-                  {...{ attachDir, macros }}
+                  {...{ attachDir, useInheritance, macros }}
                 >
                   {nodeById[link as string]?.title}
                 </PreviewLink>
diff --git a/components/Sidebar/Link.tsx b/components/Sidebar/Link.tsx
index 6130eb5..2f1ad64 100644
--- a/components/Sidebar/Link.tsx
+++ b/components/Sidebar/Link.tsx
@@ -42,6 +42,7 @@ export interface LinkProps {
   isWiki?: boolean
   noUnderline?: boolean
   attachDir: string
+  useInheritance: boolean
   macros: { [key: string]: string }
 }
 
@@ -142,6 +143,7 @@ export const PreviewLink = (props: LinkProps) => {
     isWiki,
     macros,
     attachDir,
+    useInheritance,
   } = props
   // TODO figure out how to properly type this
   // see https://github.com/rehypejs/rehype-react/issues/25
@@ -296,6 +298,7 @@ export const PreviewLink = (props: LinkProps) => {
                         linksByNodeId,
                         macros,
                         attachDir,
+                        useInheritance,
                       }}
                       previewNode={nodeById[id]!}
                       collapse={false}
diff --git a/components/Sidebar/Note.tsx b/components/Sidebar/Note.tsx
index 2b76994..638b43a 100644
--- a/components/Sidebar/Note.tsx
+++ b/components/Sidebar/Note.tsx
@@ -22,6 +22,7 @@ export interface NoteProps {
   collapse: boolean
   macros?: { [key: string]: string }
   attachDir: string
+  useInheritance: boolean
 }
 
 export const Note = (props: NoteProps) => {
@@ -39,6 +40,7 @@ export const Note = (props: NoteProps) => {
     collapse,
     macros,
     attachDir,
+    useInheritance,
   } = props
 
   const extraStyle = outline ? outlineNoteStyle : viewerNoteStyle
@@ -74,6 +76,7 @@ export const Note = (props: NoteProps) => {
               linksByNodeId,
               macros,
               attachDir,
+              useInheritance,
             }}
           />
           <Backlinks
@@ -87,6 +90,7 @@ export const Note = (props: NoteProps) => {
               openContextMenu,
               outline,
               attachDir,
+              useInheritance,
             }}
             macros={macros || {}}
           />
diff --git a/components/Sidebar/index.tsx b/components/Sidebar/index.tsx
index 66728fd..e112699 100644
--- a/components/Sidebar/index.tsx
+++ b/components/Sidebar/index.tsx
@@ -51,6 +51,7 @@ export interface SidebarProps {
   setTagColors: any
   macros?: { [key: string]: string }
   attachDir: string
+  useInheritance: boolean
 }
 
 const Sidebar = (props: SidebarProps) => {
@@ -79,6 +80,7 @@ const Sidebar = (props: SidebarProps) => {
     setTagColors,
     macros,
     attachDir,
+    useInheritance,
   } = props
 
   const { highlightColor } = useContext(ThemeContext)
@@ -231,6 +233,7 @@ const Sidebar = (props: SidebarProps) => {
                     collapse,
                     macros,
                     attachDir,
+                    useInheritance,
                   }}
                 />
               </VStack>
diff --git a/org-roam-ui.el b/org-roam-ui.el
index c56ca6f..4ac0ff4 100644
--- a/org-roam-ui.el
+++ b/org-roam-ui.el
@@ -584,6 +584,9 @@ from all other links."
           (attach-dir (if (boundp 'org-attach-id-dir)
                           org-attach-id-dir
                         (expand-file-name ".attach/" org-directory)))
+          (use-inheritance (if (boundp 'org-attach-use-inheritance)
+                            org-attach-use-inheritance
+                            nil))
           (sub-dirs (org-roam-ui-find-subdirectories)))
       (websocket-send-text org-roam-ui-ws-socket
                            (json-encode
@@ -595,6 +598,8 @@ from all other links."
                                       ,daily-dir)
                                      ("attachDir" .
                                       ,attach-dir)
+                                     ("useInheritance" .
+                                      ,use-inheritance)
                                      ("roamDir" . ,org-roam-directory)
                                      ("katexMacros" . ,org-roam-ui-latex-macros))))))))
 
diff --git a/pages/index.tsx b/pages/index.tsx
index 9b21f7b..fdbabc3 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -79,6 +79,7 @@ export interface EmacsVariables {
   dailyDir?: string
   katexMacros?: { [key: string]: string }
   attachDir?: string
+  useInheritance?: boolean,
   subDirs: string[]
 }
 export type Tags = string[]
@@ -684,6 +685,7 @@ export function GraphPage() {
             }}
             macros={emacsVariables.katexMacros}
             attachDir={emacsVariables.attachDir || ''}
+            useInheritance={emacsVariables.useInheritance || false}
             nodeById={nodeByIdRef.current!}
             linksByNodeId={linksByNodeIdRef.current!}
             nodeByCite={nodeByCiteRef.current!}
diff --git a/util/processOrg.tsx b/util/processOrg.tsx
index 611c039..ea868ee 100644
--- a/util/processOrg.tsx
+++ b/util/processOrg.tsx
@@ -50,6 +50,7 @@ export interface ProcessedOrgProps {
   linksByNodeId: LinksByNodeId
   macros: { [key: string]: string } | {}
   attachDir: string
+  useInheritance: boolean
 }
 
 export const ProcessedOrg = (props: ProcessedOrgProps) => {
@@ -66,6 +67,7 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
     linksByNodeId,
     macros,
     attachDir,
+    useInheritance,
   } = props
 
   if (!previewNode || !linksByNodeId) {
@@ -77,7 +79,7 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
     .use(extractKeywords)
     .use(attachments, {
       idDir: attachDir || undefined,
-      useInheritance: true,
+      useInheritance,
     })
     .use(uniorgSlug)
     .use(uniorg2rehype, { useSections: true })
@@ -157,6 +159,7 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => {
                   isWiki={isMarkdown}
                   macros={macros}
                   attachDir={attachDir}
+                  useInheritance={useInheritance}
                 >
                   {children}
                 </PreviewLink>
diff --git a/util/uniorg.tsx b/util/uniorg.tsx
index 6580b9c..4172d7a 100644
--- a/util/uniorg.tsx
+++ b/util/uniorg.tsx
@@ -15,6 +15,7 @@ export interface UniOrgProps {
   linksByNodeId: LinksByNodeId
   macros?: { [key: string]: string }
   attachDir: string
+  useInheritance: boolean
 }
 
 export const UniOrg = (props: UniOrgProps) => {
@@ -30,6 +31,7 @@ export const UniOrg = (props: UniOrgProps) => {
     linksByNodeId,
     macros,
     attachDir,
+    useInheritance,
   } = props
 
   const [previewText, setPreviewText] = useState('')
@@ -72,6 +74,7 @@ export const UniOrg = (props: UniOrgProps) => {
             collapse,
             linksByNodeId,
             attachDir,
+            useInheritance,
           }}
           macros={macros || {}}
         />
diff --git a/util/variablesContext.tsx b/util/variablesContext.tsx
index 5fd34b8..f6d2356 100644
--- a/util/variablesContext.tsx
+++ b/util/variablesContext.tsx
@@ -6,6 +6,7 @@ type Theme = [name: string, themeObject: { [color: string]: string }]
 const VariablesContext = createContext<EmacsVariables>({
   subDirs: ['dailies', '.attach'],
   attachDir: '.attach',
+  useInheritance: false,
   roamDir: '~/org',
   dailyDir: 'dailies',
 })
-- 
cgit v1.2.3

